Last active
August 29, 2015 14:02
-
-
Save Bouke/3dad30b8c7d2b9408b8d to your computer and use it in GitHub Desktop.
Binary Heap (Priority Queue) in Swift
This code was written when Swift didn't have access modifiers. Both var heap
and func heapify
are not part of the public API. You can only pop
items onto the heap, so the result should always be a valid binary heap.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
won't heapify fail to explore subtrees (that might violate min-heap properties) in the case where index is already the smallest? I guess it doesn't matter here since you only ever call heapify when the index is the only element that’s in violation…