- Comparator">type Comparator
- 自带的比较器
- 排序
type Comparator
type Comparator func(a, b interface{}) int
Comparator将进行类型断言(例如,请参阅IntComparator),如果a或b不是断言的类型,则会出现panic。 应该返回一个数字
negative , if a < b // 降序
zero , if a == b
positive , if a > b // 升序
自带的比较器
func ByteComparator(a, b interface{}) int
func Float32Comparator(a, b interface{}) int
func Float64Comparator(a, b interface{}) int
func Int16Comparator(a, b interface{}) int
func Int32Comparator(a, b interface{}) int
func Int64Comparator(a, b interface{}) int
func Int8Comparator(a, b interface{}) int
func IntComparator(a, b interface{}) int
func RuneComparator(a, b interface{}) int
func StringComparator(a, b interface{}) int
func TimeComparator(a, b interface{}) int
func UInt16Comparator(a, b interface{}) int
func UInt32Comparator(a, b interface{}) int
func UInt64Comparator(a, b interface{}) int
func UInt8Comparator(a, b interface{}) int
func UIntComparator(a, b interface{}) int
排序
// Sort对给定的比较器进行(就地)排序
func Sort(values []interface{}, comparator Comparator)