diff --git a/heap.go b/heap.go index bc5d2a7..fadd8a8 100644 --- a/heap.go +++ b/heap.go @@ -1,3 +1,4 @@ +// heap package BDS // 大顶堆int @@ -9,6 +10,8 @@ type IntHeap []int // 专门为矩阵设计的多路归并思想的堆结构。 type IntHeapSpec [][3]int +type IntHeapSpecM [][3]int + func (h IntHeapM) Len() int { return len(h) } func (h IntHeapM) Less(i, j int) bool { return h[i] > h[j] } func (h IntHeapM) Swap(i, j int) { h[i], h[j] = h[j], h[i] } @@ -69,3 +72,28 @@ func (h *IntHeapSpec) Top() interface{} { return (*h)[0] } + + + +func (h IntHeapSpecM) Len() int { return len(h) } +func (h IntHeapSpecM) Less(i, j int) bool { return h[i][2] > h[j][2] } +func (h IntHeapSpecM) Swap(i, j int) { h[i], h[j] = h[j], h[i] } +func (h *IntHeapSpecM) Push(x interface{}) { + result := x.([3]int) + j, y, value := result[0], result[1], result[2] + f := [3]int{ + j, y, value, + } + *h = append(*h, f) +} +func (h *IntHeapSpecM) Pop() interface{} { + old := *h + n := len(old) + x := old[n-1] + *h = old[0 : n-1] + return x +} +func (h *IntHeapSpecM) Top() interface{} { + + return (*h)[0] +} \ No newline at end of file