| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package main |
| 6 |
|
| 7 |
import ( |
| 8 |
"cmp" |
| 9 |
|
| 10 |
"github.com/emirpasic/gods/v2/trees/binaryheap" |
| 11 |
) |
| 12 |
|
| 13 |
|
| 14 |
func main() { |
| 15 |
|
| 16 |
|
| 17 |
heap := binaryheap.New[int]() |
| 18 |
heap.Push(2) |
| 19 |
heap.Push(3) |
| 20 |
heap.Push(1) |
| 21 |
heap.Values() |
| 22 |
_, _ = heap.Peek() |
| 23 |
_, _ = heap.Pop() |
| 24 |
_, _ = heap.Pop() |
| 25 |
_, _ = heap.Pop() |
| 26 |
_, _ = heap.Pop() |
| 27 |
heap.Push(1) |
| 28 |
heap.Clear() |
| 29 |
heap.Empty() |
| 30 |
heap.Size() |
| 31 |
|
| 32 |
|
| 33 |
inverseIntComparator := func(a, b int) int { |
| 34 |
return -cmp.Compare(a, b) |
| 35 |
} |
| 36 |
heap = binaryheap.NewWith(inverseIntComparator) |
| 37 |
heap.Push(2) |
| 38 |
heap.Push(3) |
| 39 |
heap.Push(1) |
| 40 |
heap.Values() |
| 41 |
} |