Psuedocode 實施
約束:
- 輸入(要排序的陣列)
- 輸入中的元素數(n)
- 鍵在 0..k-1 (k) 範圍內
- 伯爵(陣列)
虛擬碼:
for x in input:
count[key(x)] += 1
total = 0
for i in range(k):
oldCount = count[i]
count[i] = total
total += oldCount
for x in input:
output[count[key(x)]] = x
count[key(x)] += 1
return output