next up previous
Next: Up: Previous:

Pseudocode



CountingSort(A,B,k)               Time
   for i = 1 to k                  k+1
      C[i] = 0                     k
   for j = 1 to length(A)          n+1
      C[A[j]] = C[A[j]] + 1        n
   for i = 2 to k                  k
      C[i] = C[i] + C[i-1]         k-1
   for j = length(A) downto 1      n+1
      B[C[A[j]]] = A[j]            n
      C[A[j]] = C[A[j]] - 1        n


next up previous
Next: Up: Previous: