Skip to content

Instantly share code, notes, and snippets.

@roylee0704
Created May 24, 2016 05:11
Show Gist options
  • Save roylee0704/3267b01a293cddfbfb1c105ee32c5bd7 to your computer and use it in GitHub Desktop.
Save roylee0704/3267b01a293cddfbfb1c105ee32c5bd7 to your computer and use it in GitHub Desktop.
type intHeap []int
func (h intHeap) Less(i, j int) bool {
return h[i] < h[j]
}
func (h intHeap) Len() int {
return len(h)
}
func (h intHeap) Swap(i, j int) {
h[i], h[j] = h[j], h[i]
}
func (h *intHeap) Push(val int) int {
*h = append(*h, val)
}
func (h *intHeap) Pop() int {
old := *h
n := len(old)
x := old[n-1]
*h = old[0: n-1]
return x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment