 | Algorithm D (Distribution counting).
Assuming that all keys are integers in the range
u <= Kj <= v for 1 <= j <= N,
this algorithm sorts the records R1, ..., RN
by making use of an auxiliary table
COUNT[u ], ..., COUNT[v ].
At the conclusion of the algorithm the records are
moved to an output area S1, ..., SN in the
desired order.
 | [Clear COUNTs.] Set COUNT[u ]
through COUNT[v ] all to zero.
|
 | [Loop on j.] Perform step D3, for
1 <= j <= N; then go to step D4.
|
 | [Increase COUNT[Kj].]
Increase the value of COUNT[Kj]
by 1.
|
 | [Accumulate.] (At this point COUNT[i]
is the number of keys that are equal to i.)
Set COUNT[i ] <- COUNT[i ] + COUNT[i-1 ],
for i = u + 1, u + 2, ..., v.
|
 | [Loop on j.] (At this point COUNT[i]
is the number of keys that are less than or equal to i;
in particular, COUNT[v ] = N.)
Perform step D6 for j = N, N-1, ..., 1;
then terminate the algorithm.
|
 | [Output Rj.] Set i <- COUNT[Kj ], Si <- Rj, and COUNT[Kj ] <- i-1.
|
|