Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Example_intHeap ¶
func Example_intHeap()
This example inserts several ints into an IntHeap, checks the minimum, and removes them in order of priority.
func TestPriorityQueue ¶
func TestPriorityQueue()
Types ¶
type IntHeap ¶
type IntHeap []int
An IntHeap is a min-heap of ints.
func (*IntHeap) Pop ¶
func (h *IntHeap) Pop() interface{}
Pop 弹出堆顶的元素, 还记得堆是如何删除元素的吗? 1. 取出堆顶的元素给你 2. 那现在堆顶的空位应该被如何补充 3. 把堆底的元素给他, 然后就是shift-down 我们这里Pop 就是给他最后一个元素, 后面的操作由heap包的pop帮我们完成(shift-donw)
type PriorityQueue ¶
type PriorityQueue []*Item
优先级队列需要实现heap的interface
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() interface{}
绑定put方法,将index置为-1是为了标识该数据已经出了优先级队列了
Click to show internal directories.
Click to hide internal directories.