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.
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.
Example
Input : {0, 1, 2, 0, 1, 2}
Output : {0, 0, 1, 1, 2, 2}
Input : {0, 1, 1, 0, 1, 2, 1, 2, 0, 0, 0, 1}
Output : {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2}
Categorized in:
Tagged in:
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 & 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