Created
May 24, 2016 05:11
-
-
Save roylee0704/3267b01a293cddfbfb1c105ee32c5bd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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