countingSort(A, B, N): C # サイズK+1の配列 for i ← 0 to N-1: C[A[i]]++ for i ← 1 to K: C[i] ← C[i] + C[i-1] for i ← N-1 downto 0: C[A[i]]-- B[C[A[i]]] ← A[i]