<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sorting an array in c++ program - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/sorting-an-array-in-c-program/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/sorting-an-array-in-c-program/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Mon, 13 Sep 2021 12:23:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.wikitechy.com/interview-questions/wp-content/uploads/2025/10/cropped-wikitechy-icon-32x32.png</url>
	<title>sorting an array in c++ program - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/sorting-an-array-in-c-program/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>What is the best way to sort an array of 0s and 1s ?</title>
		<link>https://www.wikitechy.com/interview-questions/cpp/what-is-the-best-way-to-sort-an-array-of-0s-and-1s/</link>
					<comments>https://www.wikitechy.com/interview-questions/cpp/what-is-the-best-way-to-sort-an-array-of-0s-and-1s/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Mon, 12 Jul 2021 23:13:59 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></category>
		<category><![CDATA[all sorting programs in c++]]></category>
		<category><![CDATA[Applied Materials interview questions and answers]]></category>
		<category><![CDATA[array sort]]></category>
		<category><![CDATA[array sort c++]]></category>
		<category><![CDATA[array sorting in c]]></category>
		<category><![CDATA[arraylist sort]]></category>
		<category><![CDATA[ascending order program in c++ using for loop]]></category>
		<category><![CDATA[Atos interview questions and answers]]></category>
		<category><![CDATA[BMC Software interview questions and answers]]></category>
		<category><![CDATA[Bosch India Software interview questions and answers]]></category>
		<category><![CDATA[bubble sort c++]]></category>
		<category><![CDATA[c++ container sort]]></category>
		<category><![CDATA[c++ program to sort an array in ascending order using functionsort array c++ ascending function]]></category>
		<category><![CDATA[c++ program to sort an array in descending order]]></category>
		<category><![CDATA[c++ set sort]]></category>
		<category><![CDATA[c++ sort array]]></category>
		<category><![CDATA[c++ sort array alphabetically]]></category>
		<category><![CDATA[c++ sort custom comparator]]></category>
		<category><![CDATA[c++ sort vector of doubles]]></category>
		<category><![CDATA[c++ sort vector of strings]]></category>
		<category><![CDATA[c++ sort vector of strings alphabetically]]></category>
		<category><![CDATA[CASTING NETWORKS INDIA PVT LIMITED interview questions and answers]]></category>
		<category><![CDATA[Chetu interview questions and answers]]></category>
		<category><![CDATA[Ciena Corporation interview questions and answers]]></category>
		<category><![CDATA[compro technologies interview questions and answers]]></category>
		<category><![CDATA[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[eInfochips interview questions and answers]]></category>
		<category><![CDATA[Electronics Arts Inc interview questions and answers]]></category>
		<category><![CDATA[Flipkart interview questions and answers]]></category>
		<category><![CDATA[Harman International interview questions and answers]]></category>
		<category><![CDATA[how to sort an array]]></category>
		<category><![CDATA[how to sort an array in c++]]></category>
		<category><![CDATA[Indecomm Global Services interview questions and answers]]></category>
		<category><![CDATA[Larsen & Toubro interview questions and answers]]></category>
		<category><![CDATA[Mathworks India Private Limited interview questions and answers]]></category>
		<category><![CDATA[Mavenir interview questions and answers]]></category>
		<category><![CDATA[Mphasis interview questions and answers]]></category>
		<category><![CDATA[NetApp interview questions and answers]]></category>
		<category><![CDATA[Oracle Corporation interview questions and answers]]></category>
		<category><![CDATA[PeopleStrong interview questions and answers]]></category>
		<category><![CDATA[Philips Software Centre Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[q sort function in c++]]></category>
		<category><![CDATA[sort array c++ ascending]]></category>
		<category><![CDATA[sort deque c++]]></category>
		<category><![CDATA[sort float vector c++]]></category>
		<category><![CDATA[sort function in c]]></category>
		<category><![CDATA[sort part of array c++]]></category>
		<category><![CDATA[sort part of vector c++]]></category>
		<category><![CDATA[sort string array in java]]></category>
		<category><![CDATA[sort vector in descending order c++]]></category>
		<category><![CDATA[sorting an array in c++ program]]></category>
		<category><![CDATA[SRM Technologies interview questions and answers]]></category>
		<category><![CDATA[Symphony Teleca interview questions and answers]]></category>
		<category><![CDATA[Tech Mahindra interview questions and answers]]></category>
		<category><![CDATA[Tecnotree interview questions and answers]]></category>
		<category><![CDATA[Wipro Infotech interview questions and answers]]></category>
		<category><![CDATA[Wipro interview questions and answers]]></category>
		<category><![CDATA[Yash Technologies interview questions and answers]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=398</guid>

					<description><![CDATA[Answer : Sort an array elements means arrange...]]></description>
										<content:encoded><![CDATA[<div class="TextHeading">
<div class="hddn">
<h2 id="what-is-the-best-way-to-sort-an-array-of-0s-and-1s" class="color-pink" style="text-align: justify;">What is the best way to sort an array of 0s and 1s ?</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li><a href="https://www.wikitechy.com/tutorials/java/how-to-sort-string-array-in-java" target="_blank" rel="noopener">Sort an array</a> elements means arrange elements of array in <a href="https://www.wikitechy.com/angularjs/angularjs-orderby-filter" target="_blank" rel="noopener">ascending order and descending order</a>.</li>
</ul>
</div>
</div>
<p style="text-align: justify;">Given an array A[] consisting 0s, 1s and 2s, write a function that sorts A[]. The functions should put all 0s first, then all 1s and all 2s in last.</p>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="example" class="color-purple">Example</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-cpp code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-cpp code-embed-code">Input :  {0, 1, 2, 0, 1, 2}<br/>Output : {0, 0, 1, 1, 2, 2}<br/>Input :  {0, 1, 1, 0, 1, 2, 1, 2, 0, 0, 0, 1}<br/>Output : {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2}</code></pre> </div>
</div>
</div>
<div class="Output" style="text-align: justify;">
<div class="hddn">
<figure class="highlight">
<pre><code class="hljs" data-lang=""></code><img decoding="async" class="img-responsive center-block aligncenter" src="https://cdn.wikitechy.com/interview-questions/cpp/sort-an-array-of-0s-and-1s.gif" alt=" Sort" /></pre>
</figure>
</div>
</div>
<div class="CodeContent" style="text-align: justify;">
<div class="hddn">
<figure class="highlight">
<div class="TextHeading">
<div class="hddn">
<h2 id="sample-code-in-c" class="color-purple">Sample code in C++</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-cpp code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-cpp code-embed-code">#include &lt;bits/stdc++.h&gt;<br/>using namespace std; <br/>  <br/>// Function to segregate 0s and 1s <br/>void segregate0and1(intarr[], int n) <br/>{ <br/>    int count = 0; // Counts the no of zeros in arr<br/>  	<br/>    for (inti = 0; i&lt; n; i++) { <br/>        if (arr[i] == 0) <br/>            count++; <br/>    } <br/>  <br/>    // Loop fills the arr with 0 until count <br/>    for (inti = 0; i&lt; count; i++) <br/>        arr[i] = 0; <br/>  <br/>    // Loop fills remaining arr space with 1 <br/>    for (inti = count; i&lt; n; i++) <br/>        arr[i] = 1; <br/>} <br/>  <br/>// Function to print segregated array <br/>void print(intarr[], int n) <br/>{ <br/>    cout&lt;&lt; &quot;Array after segregation is &quot;; <br/>  <br/>    for (inti = 0; i&lt; n; i++) <br/>        cout&lt;&lt;arr[i] &lt;&lt; &quot; &quot;; <br/>} <br/>  <br/>// Driver function <br/>int main() <br/>{ <br/>    intarr[] = { 0, 1, 0, 1, 1, 1 }; <br/>    int n = sizeof(arr) / sizeof(arr[0]); <br/>      <br/>    segregate0and1(arr, n); <br/>    print(arr, n); <br/>      <br/>    return 0; <br/>} </code></pre> </div>
<div class="TextHeading">
<div class="hddn">
<h2 id="output" class="color-purple">Output</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-cpp code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-cpp code-embed-code">Array after segregation is 0 0 1 1 1 1</code></pre> </div>
</div>
</div>
</div>
</div>
</figure>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/cpp/what-is-the-best-way-to-sort-an-array-of-0s-and-1s/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
