Skip to content

Instantly share code, notes, and snippets.

@robbie01
Last active December 31, 2016 23:31
Show Gist options
  • Save robbie01/932742cf57e48687472eebb97f01ae77 to your computer and use it in GitHub Desktop.
Save robbie01/932742cf57e48687472eebb97f01ae77 to your computer and use it in GitHub Desktop.
Heap sort implemented in Python 3
from heapq import heapify, heappop #is this cheating?
def heapsort(list):
heap = heapify(list)
newList = []
while heap:
newList.append(heappop(heap))
return newList
if __name__ == '__main__':
from sys import argv
from random import shuffle
list = list(range(int(argv[1])))
shuffle(list)
list = heapsort(list)
print(all(list[i] <= list[i+1] for i in range(len(list)-1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment