{"id":398,"date":"2021-07-12T23:13:59","date_gmt":"2021-07-12T23:13:59","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=398"},"modified":"2021-09-13T12:23:45","modified_gmt":"2021-09-13T12:23:45","slug":"what-is-the-best-way-to-sort-an-array-of-0s-and-1s","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/","title":{"rendered":"What is the best way to sort an array of 0s and 1s ?"},"content":{"rendered":"<div class=\"TextHeading\">\n<div class=\"hddn\">\n<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>\n<\/div>\n<\/div>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<ul>\n<li><a href=\"https:\/\/www.wikitechy.com\/tutorials\/java\/how-to-sort-string-array-in-java\" target=\"_blank\" rel=\"noopener\">Sort an array<\/a>\u00a0elements means arrange elements of array in\u00a0<a href=\"https:\/\/www.wikitechy.com\/angularjs\/angularjs-orderby-filter\" target=\"_blank\" rel=\"noopener\">ascending order and descending order<\/a>.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<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>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"example\" class=\"color-purple\">Example<\/h2>\n<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>\n<\/div>\n<\/div>\n<div class=\"Output\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<figure class=\"highlight\">\n<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>\n<\/figure>\n<\/div>\n<\/div>\n<div class=\"CodeContent\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<figure class=\"highlight\">\n<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"sample-code-in-c\" class=\"color-purple\">Sample code in C++<\/h2>\n<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 <bits\/stdc++.h><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\/>  \t<br\/>    for (inti = 0; i< 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< count; i++) <br\/>        arr[i] = 0; <br\/>  <br\/>    \/\/ Loop fills remaining arr space with 1 <br\/>    for (inti = count; i< n; i++) <br\/>        arr[i] = 1; <br\/>} <br\/>  <br\/>\/\/ Function to print segregated array <br\/>void print(intarr[], int n) <br\/>{ <br\/>    cout<< &quot;Array after segregation is &quot;; <br\/>  <br\/>    for (inti = 0; i< n; i++) <br\/>        cout<<arr[i] << &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>\n<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"output\" class=\"color-purple\">Output<\/h2>\n<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>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/figure>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Answer : Sort an array elements means arrange&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2080],"tags":[195,2466,491,2467,2469,2468,2471,2465,360,368,211,2457,2477,2463,2459,2479,2472,2461,2480,2482,2456,2458,199,198,363,15938,205,2117,220,222,2122,2474,2473,212,2120,2121,710,207,366,204,217,2116,2475,2462,2478,2481,2455,2460,2476,2470,2464,2454,2123,210,200,2118,968,216,2119],"class_list":["post-398","post","type-post","status-publish","format-standard","hentry","category-cpp","tag-accenture-interview-questions-and-answers","tag-all-sorting-programs-in-c","tag-applied-materials-interview-questions-and-answers","tag-array-sort","tag-array-sort-c","tag-array-sorting-in-c","tag-arraylist-sort","tag-ascending-order-program-in-c-using-for-loop","tag-atos-interview-questions-and-answers","tag-bmc-software-interview-questions-and-answers","tag-bosch-india-software-interview-questions-and-answers","tag-bubble-sort-c","tag-c-container-sort","tag-c-program-to-sort-an-array-in-ascending-order-using-functionsort-array-c-ascending-function","tag-c-program-to-sort-an-array-in-descending-order","tag-c-set-sort","tag-c-sort-array","tag-c-sort-array-alphabetically","tag-c-sort-custom-comparator","tag-c-sort-vector-of-doubles","tag-c-sort-vector-of-strings","tag-c-sort-vector-of-strings-alphabetically","tag-casting-networks-india-pvt-limited-interview-questions-and-answers","tag-chetu-interview-questions-and-answers","tag-ciena-corporation-interview-questions-and-answers","tag-compro-technologies-interview-questions-and-answers","tag-dell-international-services-india-pvt-ltd-interview-questions-and-answers","tag-einfochips-interview-questions-and-answers","tag-electronics-arts-inc-interview-questions-and-answers","tag-flipkart-interview-questions-and-answers","tag-harman-international-interview-questions-and-answers","tag-how-to-sort-an-array","tag-how-to-sort-an-array-in-c","tag-indecomm-global-services-interview-questions-and-answers","tag-larsen-toubro-interview-questions-and-answers","tag-mathworks-india-private-limited-interview-questions-and-answers","tag-mavenir-interview-questions-and-answers","tag-mphasis-interview-questions-and-answers","tag-netapp-interview-questions-and-answers","tag-oracle-corporation-interview-questions-and-answers","tag-peoplestrong-interview-questions-and-answers","tag-philips-software-centre-pvt-ltd-interview-questions-and-answers","tag-q-sort-function-in-c","tag-sort-array-c-ascending","tag-sort-deque-c","tag-sort-float-vector-c","tag-sort-function-in-c","tag-sort-part-of-array-c","tag-sort-part-of-vector-c","tag-sort-string-array-in-java","tag-sort-vector-in-descending-order-c","tag-sorting-an-array-in-c-program","tag-srm-technologies-interview-questions-and-answers","tag-symphony-teleca-interview-questions-and-answers","tag-tech-mahindra-interview-questions-and-answers","tag-tecnotree-interview-questions-and-answers","tag-wipro-infotech-interview-questions-and-answers","tag-wipro-interview-questions-and-answers","tag-yash-technologies-interview-questions-and-answers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What is the best way to sort an array of 0s and 1s ? - C++<\/title>\n<meta name=\"description\" content=\"What is the best way to sort an array of 0s and 1s ? - Sort an array elements means arrange elements of array in ascending order and descending order.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is the best way to sort an array of 0s and 1s ? - C++\" \/>\n<meta property=\"og:description\" content=\"What is the best way to sort an array of 0s and 1s ? - Sort an array elements means arrange elements of array in ascending order and descending order.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-12T23:13:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-13T12:23:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.wikitechy.com\/interview-questions\/cpp\/sort-an-array-of-0s-and-1s.gif\" \/>\n<meta name=\"author\" content=\"Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\\\/\"},\"author\":{\"name\":\"Editor\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/4d5a581fb5470d1560324bddc5e8b757\"},\"headline\":\"What is the best way to sort an array of 0s and 1s ?\",\"datePublished\":\"2021-07-12T23:13:59+00:00\",\"dateModified\":\"2021-09-13T12:23:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\\\/\"},\"wordCount\":394,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/cdn.wikitechy.com\\\/interview-questions\\\/cpp\\\/sort-an-array-of-0s-and-1s.gif\",\"keywords\":[\"Accenture interview questions and answers\",\"all sorting programs in c++\",\"Applied Materials interview questions and answers\",\"array sort\",\"array sort c++\",\"array sorting in c\",\"arraylist sort\",\"ascending order program in c++ using for loop\",\"Atos interview questions and answers\",\"BMC Software interview questions and answers\",\"Bosch India Software interview questions and answers\",\"bubble sort c++\",\"c++ container sort\",\"c++ program to sort an array in ascending order using functionsort array c++ ascending function\",\"c++ program to sort an array in descending order\",\"c++ set sort\",\"c++ sort array\",\"c++ sort array alphabetically\",\"c++ sort custom comparator\",\"c++ sort vector of doubles\",\"c++ sort vector of strings\",\"c++ sort vector of strings alphabetically\",\"CASTING NETWORKS INDIA PVT LIMITED interview questions and answers\",\"Chetu interview questions and answers\",\"Ciena Corporation interview questions and answers\",\"compro technologies interview questions and answers\",\"Dell International Services India Pvt Ltd interview questions and answers\",\"eInfochips interview questions and answers\",\"Electronics Arts Inc interview questions and answers\",\"Flipkart interview questions and answers\",\"Harman International interview questions and answers\",\"how to sort an array\",\"how to sort an array in c++\",\"Indecomm Global Services interview questions and answers\",\"Larsen &amp; Toubro interview questions and answers\",\"Mathworks India Private Limited interview questions and answers\",\"Mavenir interview questions and answers\",\"Mphasis interview questions and answers\",\"NetApp interview questions and answers\",\"Oracle Corporation interview questions and answers\",\"PeopleStrong interview questions and answers\",\"Philips Software Centre Pvt Ltd interview questions and answers\",\"q sort function in c++\",\"sort array c++ ascending\",\"sort deque c++\",\"sort float vector c++\",\"sort function in c\",\"sort part of array c++\",\"sort part of vector c++\",\"sort string array in java\",\"sort vector in descending order c++\",\"sorting an array in c++ program\",\"SRM Technologies interview questions and answers\",\"Symphony Teleca interview questions and answers\",\"Tech Mahindra interview questions and answers\",\"Tecnotree interview questions and answers\",\"Wipro Infotech interview questions and answers\",\"Wipro interview questions and answers\",\"Yash Technologies interview questions and answers\"],\"articleSection\":[\"C++\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\\\/\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\\\/\",\"name\":\"What is the best way to sort an array of 0s and 1s ? - C++\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/cdn.wikitechy.com\\\/interview-questions\\\/cpp\\\/sort-an-array-of-0s-and-1s.gif\",\"datePublished\":\"2021-07-12T23:13:59+00:00\",\"dateModified\":\"2021-09-13T12:23:45+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/4d5a581fb5470d1560324bddc5e8b757\"},\"description\":\"What is the best way to sort an array of 0s and 1s ? - Sort an array elements means arrange elements of array in ascending order and descending order.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\\\/#primaryimage\",\"url\":\"https:\\\/\\\/cdn.wikitechy.com\\\/interview-questions\\\/cpp\\\/sort-an-array-of-0s-and-1s.gif\",\"contentUrl\":\"https:\\\/\\\/cdn.wikitechy.com\\\/interview-questions\\\/cpp\\\/sort-an-array-of-0s-and-1s.gif\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#website\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/4d5a581fb5470d1560324bddc5e8b757\",\"name\":\"Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"caption\":\"Editor\"},\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/author\\\/editor\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is the best way to sort an array of 0s and 1s ? - C++","description":"What is the best way to sort an array of 0s and 1s ? - Sort an array elements means arrange elements of array in ascending order and descending order.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/","og_locale":"en_US","og_type":"article","og_title":"What is the best way to sort an array of 0s and 1s ? - C++","og_description":"What is the best way to sort an array of 0s and 1s ? - Sort an array elements means arrange elements of array in ascending order and descending order.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/","og_site_name":"Wikitechy","article_published_time":"2021-07-12T23:13:59+00:00","article_modified_time":"2021-09-13T12:23:45+00:00","og_image":[{"url":"https:\/\/cdn.wikitechy.com\/interview-questions\/cpp\/sort-an-array-of-0s-and-1s.gif","type":"","width":"","height":""}],"author":"Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Editor","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/#article","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/"},"author":{"name":"Editor","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757"},"headline":"What is the best way to sort an array of 0s and 1s ?","datePublished":"2021-07-12T23:13:59+00:00","dateModified":"2021-09-13T12:23:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/"},"wordCount":394,"commentCount":0,"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.wikitechy.com\/interview-questions\/cpp\/sort-an-array-of-0s-and-1s.gif","keywords":["Accenture interview questions and answers","all sorting programs in c++","Applied Materials interview questions and answers","array sort","array sort c++","array sorting in c","arraylist sort","ascending order program in c++ using for loop","Atos interview questions and answers","BMC Software interview questions and answers","Bosch India Software interview questions and answers","bubble sort c++","c++ container sort","c++ program to sort an array in ascending order using functionsort array c++ ascending function","c++ program to sort an array in descending order","c++ set sort","c++ sort array","c++ sort array alphabetically","c++ sort custom comparator","c++ sort vector of doubles","c++ sort vector of strings","c++ sort vector of strings alphabetically","CASTING NETWORKS INDIA PVT LIMITED interview questions and answers","Chetu interview questions and answers","Ciena Corporation interview questions and answers","compro technologies interview questions and answers","Dell International Services India Pvt Ltd interview questions and answers","eInfochips interview questions and answers","Electronics Arts Inc interview questions and answers","Flipkart interview questions and answers","Harman International interview questions and answers","how to sort an array","how to sort an array in c++","Indecomm Global Services interview questions and answers","Larsen &amp; Toubro interview questions and answers","Mathworks India Private Limited interview questions and answers","Mavenir interview questions and answers","Mphasis interview questions and answers","NetApp interview questions and answers","Oracle Corporation interview questions and answers","PeopleStrong interview questions and answers","Philips Software Centre Pvt Ltd interview questions and answers","q sort function in c++","sort array c++ ascending","sort deque c++","sort float vector c++","sort function in c","sort part of array c++","sort part of vector c++","sort string array in java","sort vector in descending order c++","sorting an array in c++ program","SRM Technologies interview questions and answers","Symphony Teleca interview questions and answers","Tech Mahindra interview questions and answers","Tecnotree interview questions and answers","Wipro Infotech interview questions and answers","Wipro interview questions and answers","Yash Technologies interview questions and answers"],"articleSection":["C++"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/","name":"What is the best way to sort an array of 0s and 1s ? - C++","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.wikitechy.com\/interview-questions\/cpp\/sort-an-array-of-0s-and-1s.gif","datePublished":"2021-07-12T23:13:59+00:00","dateModified":"2021-09-13T12:23:45+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757"},"description":"What is the best way to sort an array of 0s and 1s ? - Sort an array elements means arrange elements of array in ascending order and descending order.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-the-best-way-to-sort-an-array-of-0s-and-1s\/#primaryimage","url":"https:\/\/cdn.wikitechy.com\/interview-questions\/cpp\/sort-an-array-of-0s-and-1s.gif","contentUrl":"https:\/\/cdn.wikitechy.com\/interview-questions\/cpp\/sort-an-array-of-0s-and-1s.gif"},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757","name":"Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","caption":"Editor"},"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=398"}],"version-history":[{"count":3,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/398\/revisions"}],"predecessor-version":[{"id":3596,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/398\/revisions\/3596"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}