(arr []T)
| 44 | } |
| 45 | |
| 46 | func 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 | } |
nothing calls this directly
no test coverage detected