go切片的sort排序

点击查看代码
package main

import(
	"fmt"
	"sort"	
)


func main(){	
	var a [5]int = [5]int {5,4,3,2,1}
	sort.Ints(a[:])
	fmt.Println("a",a)

	var b [5]string = [5]string {"ac","ec","be","fa","ii"}
	sort.Strings(b[:])
	fmt.Println("b",b)

	var c [5]float64 = [5]float64{29.38, 22.32, 0.8, 991.92, 93.33}
	sort.Float64s(c[:])
	fmt.Println("c",c)
}

输出:

点击查看代码
a [1 2 3 4 5]
b [ac be ec fa ii]
c [0.8 22.32 29.38 93.33 991.92]
posted @ 2022-03-05 18:39  ty1539  阅读(66)  评论(0编辑  收藏  举报