Created
May 3, 2022 03:03
-
-
Save sausheong/b539b8f1b38c57c11b86edff4e511a78 to your computer and use it in GitHub Desktop.
mst
This file contains hidden or 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 Heap []NodePair | |
| func (h Heap) Len() int { return len(h) } | |
| func (h Heap) Less(i, j int) bool { return h[i].edge.weight < h[j].edge.weight } | |
| func (h Heap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } | |
| func (h *Heap) Push(x any) { *h = append(*h, x.(NodePair)) } | |
| func (h *Heap) Pop() any { | |
| old := *h | |
| n := len(old) | |
| item := old[n-1] | |
| *h = old[0 : n-1] | |
| return item | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment