package main
import (
"fmt"
"sort"
)
func main() {
mapInfo := map[string]int32{
"roy":18,
"kitty":16,
"hugo":21,
"tina":35,
"jason":23,
}
type peroson struct {
Name string
Age int32
}
var lstPerson []peroson
for k, v := range mapInfo {
lstPerson = append(lstPerson, peroson {k, v})
}
sort.Slice(lstPerson, func(i, j int) bool {
return lstPerson[i].Age > lstPerson[j].Age // 降序
// return lstPerson[i].Age < lstPerson[j].Age // 升序
})
fmt.Println(lstPerson)
}