Counting methods for sorting

Hide text Hide pseudo-code

Sort the following array of key values by means of counting sort.

Some additional problems.

 1. for (j=0; j<M; j++)
 2.   aux[j] = 0;
 3. for (i=0; i<N; i++) 
 4.   aux[input[i]]++;
 5. for (j=1; j<M; j++)
 6.   aux[j] += aux[j-1];
 7. for (i=N-1; i>=0; i--) { 
 8.   output[aux[input[i]]] = input[i];
 9.   aux[input[i]]--;
10. }


  Created Fri Oct 30 13:52:50 EET 2009 - Powered by SVG-hut