sort包中提供了很多排序算法,对自定义类型进行排序时,只需要实现sort的Interface即可,包括: func Len() int {... } func Swap(i, j int) {... } func Less(i, j int) bool {... } 使用方法举例如下: package main import ( "fmt" "sort" ) type Person struct { Name string Age int } func (p Pe
综述 变量声明时未赋初值,则变量被自动赋值为该类型的零值(固定值) func new(Type) *Type new()返回一个指针,指向新分配的该类型的零值,不是空指针(nil).the value returned is a pointer to a newly allocated zero value of that type. func make(t Type, size ...IntegerType) Type make()只适用于slice.map.chan,此三种类型创建时推荐使用