MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / countSort

Function countSort

sort/radixsort.go:16–33  ·  view source on GitHub ↗
(arr []T, exp T)

Source from the content-addressed store, hash-verified

14)
15
16func countSort[T constraints.Integer](arr []T, exp T) []T {
17 var digits [10]int
18 var output = make([]T, len(arr))
19
20 for _, item := range arr {
21 digits[(item/exp)%10]++
22 }
23 for i := 1; i < 10; i++ {
24 digits[i] += digits[i-1]
25 }
26
27 for i := len(arr) - 1; i >= 0; i-- {
28 output[digits[(arr[i]/exp)%10]-1] = arr[i]
29 digits[(arr[i]/exp)%10]--
30 }
31
32 return output
33}
34
35func unsignedRadixSort[T constraints.Integer](arr []T) []T {
36 if len(arr) == 0 {

Callers 1

unsignedRadixSortFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected