Skip to content

Commit 905a58f

Browse files
committed
修改golang版CountingSort, 修改为从后向前遍历, 使其成为稳定排序
1 parent 6c02e93 commit 905a58f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

go/14_sorts/CountingSort.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func CountingSort(a []int, n int) {
2323
}
2424

2525
r := make([]int, n)
26-
for i := range a {
26+
for i := n - 1; i >= 0; i-- {
2727
index := c[a[i]] - 1
2828
r[index] = a[i]
2929
c[a[i]]--

0 commit comments

Comments
 (0)