sort.Ints是对几个int进行排序的便捷函数。通常,如果要对某些内容进行排序和排序,则需要实现sort.Interface接口.Reverse只是返回该接口的另一种实现,该实现重新定义了
Less方法。
幸运的是,sort程序包包含一个称为IntSlice的预定义类型,该类型实现了sort.Interface:
keys := []int{3, 2, 8, 1}sort.Sort(sort.Reverse(sort.IntSlice(keys)))fmt.Println(keys)
sort.Ints是对几个int进行排序的便捷函数。通常,如果要对某些内容进行排序和排序,则需要实现sort.Interface接口.Reverse只是返回该接口的另一种实现,该实现重新定义了
Less方法。
幸运的是,sort程序包包含一个称为IntSlice的预定义类型,该类型实现了sort.Interface:
keys := []int{3, 2, 8, 1}sort.Sort(sort.Reverse(sort.IntSlice(keys)))fmt.Println(keys)