COUNTING_SORT(A) For i = 0 to k C[i] = 0 EndFor For i = 1 to A.size-1 C[A[i]]++ EndFor For i = 1 to k C[i] = C[i] + C[i-1] EndFor For j = A.size-1 downto 0 C[A[j]] -- B[C[A[j]]] = A[j] EndFor