Last active
December 31, 2016 23:31
-
-
Save robbie01/932742cf57e48687472eebb97f01ae77 to your computer and use it in GitHub Desktop.
Heap sort implemented in Python 3
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
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