以下代碼應創建一個 ints ( ) 數組a并對其進行排序,但 sort.Sort 似乎并未修改該變量。package mainimport ( "fmt" "sort")type IntArray [5]inttype byNum [5]intfunc (s byNum) Len() int { return len(s)}func (s byNum) Swap(i, j int) { s[i], s[j] = s[j], s[i]}func (s byNum) Less(i, j int) bool { return s[i] < s[j]}func main() { a := IntArray{5,3,4,1,2} fmt.Println(a) sort.Sort(byNum(a)) fmt.Println(a)}https://play.golang.org/p/bhcwgosqvis[5 3 4 1 2][5 3 4 1 2]Program exited.為什么這不起作用?
- 1 回答
- 0 關注
- 146 瀏覽
添加回答
舉報
0/150
提交
取消