Leszámláló rendezés (Counting sort)

Animáció

Struktogram

$RadixSort(L : dDigitNumber <>; d : \mathbb{N})$

$i .= 1 \space to \space d$
stable sort on digit $i$

$CountingSort(A,B : \mathcal{T} [n]; r : \mathbb{N}; \varphi : \mathcal{T} \rightarrow [0..r))$

$C : \mathbb{N}[r]$
$k:= 0 \space to \space r-1$
$C[k] := 0$
$i := 0 \space to \space n-1$
$C[\varphi (A[i])]++$
$k := 1 \space to \space r-1$
$C[k] += C[k-1]$
$i := n-1 \space downto \space 0$
$k := \varphi (A[i])$
$C[k]--$
$B[C[k]] := A[i]$

Feladatok