Created
September 29, 2018 12:25
-
-
Save GuanshanLiu/30166eb1017e148cecbe69b59c11d1ea 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
extension Heap { | |
static func sort(_ elements: [Element], sort: @escaping (Element, Element) -> Bool) -> [Element] { | |
var heap = Heap(sort: sort) | |
for e in elements { | |
heap.insert(e) | |
} | |
var result = [Element]() | |
while !heap.isEmpty { | |
result.append(heap.remove()!) | |
} | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment