Skip to content

Commit 86c6f68

Browse files
committed
堆排序heapq
1 parent be9e51a commit 86c6f68

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

heap_sort.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /usr/bin/evn python
2+
#coding:utf-8
3+
4+
from heapq import *
5+
6+
def heapsort(iterable):
7+
h = []
8+
for value in iterable:
9+
heappush(h,value)
10+
return [heappop(h) for i in range(len(h))]
11+
12+
if __name__=="__main__":
13+
print heapsort([1,3,5,9,2])

0 commit comments

Comments
 (0)