-
Notifications
You must be signed in to change notification settings - Fork 0
/
comp++.go
66 lines (53 loc) · 1005 Bytes
/
comp++.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"container/heap"
"sort"
)
// Pair
/*=====================================*/
type pair struct {
x int
y int
}
func makePair(x, y int) *pair {
p := pair{x: x, y: y}
return &p
}
/*=====================================*/
// pq
/*=====================================*/
type MaxHeap []int
func (h MaxHeap) Len() int { return len(h) }
func (h MaxHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h MaxHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
func (h *MaxHeap) Push(x interface{}) {
*h = append(*h, x.(int))
}
func (h *MaxHeap) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
*h = old[0 : n-1]
return x
}
func remove(h *MaxHeap, value int) {
for i, v := range *h {
if v == value {
*h = append((*h)[:i], (*h)[i+1:]...)
heap.Init(h)
break
}
}
}
/*
declaring :
pq := &MaxHeap{0}
heap.Init(pq)
heap.Push(pq, -s.y);
remove(pq, s.y);
*/
/*=====================================*/
func main(){
return 1;
}