堆排序(Python版)

coding:utf-8

'''
堆排序的实现
'''
import heapq
def HeapSort(list):
heapq.heapify(list)
heap = []
while list:
heap.append(heapq.heappop(list))
list[:] = heap
print list

'''
test
'''
mylist=[1,4,2,3,9,4,5,3]
HeapSort(mylist)

posted @ 2016-01-12 10:20  gopher-lin  阅读(124)  评论(0编辑  收藏  举报