package main标签:sort,map,nums,fmt,num,stuScore,go,排序 From: https://www.cnblogs.com/zhutao2014/p/16724996.html
import (
"fmt"
"sort"
)
func main() {
//待排序队列
var stuScore = map[int]string{1:"ee",5:"cc",4:"ff",9:"qq",3:"aa",2:"bb"}
fmt.Println(stuScore) //map[1:ee 2:bb 3:aa 4:ff 5:cc 9:qq]
nums:=make([]int,0)
for k:=range stuScore{
nums=append(nums,k)
}
sort.Sort(sort.Reverse(sort.IntSlice(nums)))
fmt.Println(nums) //[9 5 4 3 2 1]
for _,num:=range nums {
fmt.Println(num,stuScore[num])
}