Skip to content

Instantly share code, notes, and snippets.

@garethng
Last active November 26, 2020 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garethng/a0ccc3287bc85315521e25fa6227063c to your computer and use it in GitHub Desktop.
Save garethng/a0ccc3287bc85315521e25fa6227063c to your computer and use it in GitHub Desktop.
radixSort golang 基数排序
func radixSort(nums []int) []int{
maxValue := maxValueOfList(nums...)
a := 1
for k:=0;a<=maxValue;k++{
buckets := map[int][]int{}
for i:=0;i<10;i++{
buckets[i] = []int{}
}
for _,num := range nums{
d := num / a % 10
buckets[d] = append(buckets[d], num)
}
nums = []int{}
for v:=0;v<10;v++{
nums = append(nums, buckets[v]...)
}
a *= 10
}
return nums
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment