MCPcopy Create free account
hub / github.com/0xAX/go-algorithms / CountingSort

Function CountingSort

sorting/counting_sort.go:23–42  ·  view source on GitHub ↗
(arr []int)

Source from the content-addressed store, hash-verified

21}
22
23func CountingSort(arr []int) {
24 k := getK(arr)
25 array_of_counts := make([]int, k)
26
27 for i:= 0; i < len(arr); i++ {
28 array_of_counts[arr[i]] += 1
29 }
30
31 for i, j := 0, 0; i < k; i++ {
32 for {
33 if array_of_counts[i] > 0 {
34 arr[j] = i
35 j += 1
36 array_of_counts[i] -= 1
37 continue
38 }
39 break
40 }
41 }
42}

Callers

nothing calls this directly

Calls 1

getKFunction · 0.85

Tested by

no test coverage detected