Created
September 3, 2014 15:01
-
-
Save fmasanori/4ea20c6ef0cce1f1c634 to your computer and use it in GitHub Desktop.
Python Heapsort
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
from heapq import heappush, heappop | |
def heapsort(v): | |
h = [] | |
for x in v: | |
heappush(h, x) | |
return [heappop(h) for i in range(len(h))] | |
from random import shuffle | |
v = list(range(8)) | |
shuffle(v) | |
print (v) | |
v = heapsort(v) | |
print (v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment