Go语言的堆排序实现
关于堆排序的算法,可以参考我去年的文章《堆排序(HEAP SORT)》。那篇文章讲的是建立小顶堆进行的排序,这里说的是建立大顶堆建立的排序,差不多。 在Golang源码的sort包里,自带了排序函数。该函数可以对各种类型进行排序,只不过该类型需要实现三个函数,使得该类能够实现Interface接口。 type Interface interface { // Len is the number of elements in the collection. Len() int // Less reports whether the element with // index i should sort before the element with index j. Less(i, j int...阅读全文