Skip to content

Instantly share code, notes, and snippets.

@fmasanori
Created September 3, 2014 15:01
Show Gist options
  • Save fmasanori/4ea20c6ef0cce1f1c634 to your computer and use it in GitHub Desktop.
Save fmasanori/4ea20c6ef0cce1f1c634 to your computer and use it in GitHub Desktop.
Python Heapsort
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