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

Function RadixSort

sort/radixsort.go:46–66  ·  view source on GitHub ↗
(arr []T)

Source from the content-addressed store, hash-verified

44}
45
46func RadixSort[T constraints.Integer](arr []T) []T {
47 if len(arr) < 1 {
48 return arr
49 }
50 var negatives, nonNegatives []T
51
52 for _, item := range arr {
53 if item < 0 {
54 negatives = append(negatives, -item)
55 } else {
56 nonNegatives = append(nonNegatives, item)
57 }
58 }
59 negatives = unsignedRadixSort(negatives)
60
61 // Reverse the negative array and restore signs
62 for i, j := 0, len(negatives)-1; i <= j; i, j = i+1, j-1 {
63 negatives[i], negatives[j] = -negatives[j], -negatives[i]
64 }
65 return append(negatives, unsignedRadixSort(nonNegatives)...)
66}

Callers

nothing calls this directly

Calls 1

unsignedRadixSortFunction · 0.85

Tested by

no test coverage detected