Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. type MaxHeap []int
  2.  
  3. func (h MaxHeap) Less(i, j int) bool {
  4. return h[i] < h[j]
  5. }
  6.  
  7. func (h MaxHeap) Swap(i, j int) {
  8. h[i], h[j] = h[j], h[i]
  9. }
  10.  
  11. func (h MaxHeap) Len() int {
  12. return len(h)
  13. }
  14.  
  15. func (h *MaxHeap) Push(i interface{}) {
  16. *h = append(*h, i.(int))
  17. }
  18.  
  19. func (h *MaxHeap) Pop() interface{} {
  20. item := (*h)[len(*h)-1]
  21. *h = (*h)[:len(*h)-1]
  22. return item
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement