counting sort Anil
On Wed, Jun 30, 2010 at 12:43 PM, ankur aggarwal <[email protected]>wrote: > dutch flag problem.. > > > On Wed, Jun 30, 2010 at 8:07 AM, Gene <[email protected]> wrote: > >> On Jun 29, 3:26 pm, sharad kumar <[email protected]> wrote: >> > how to sort an array containing 0's 1's and 2's in O(n)time and sorting >> > technique must be inplace >> >> #define M 3 >> >> void sort(int *a, int n) >> { >> int i, j, c[M]; >> for (j = 0; j < M; j++) c[j] = 0; >> for (i = 0; i < n; i++) ++c[a[i]]; >> for (i = j = 0; j < M; j++) >> while (c[j]--) >> a[i++] = j; >> } >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<algogeeks%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > > > -- > With Regards > > Ankur Aggarwal > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<algogeeks%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
