예제 #1
0
def heapsort(data,comp=lambda a,b:a>b):
    for i in reversed(range(len(data)//2)):
        heap.pushdown(data,i)
    last = len(data)-1
    for i in range(len(data)):
        data.enqueue(heap.pop(data,last))
        last-=1
예제 #2
0
파일: list.py 프로젝트: NightBlues/training
 def pop(self):
     return heap.pop(self.data, comp=self.comp)
예제 #3
0
파일: heap.py 프로젝트: NightBlues/training
import sys
sys.path.append('..')
import datastruct.heap as heap
from random import shuffle

# data = [x for x in range(10)]
# shuffle(data)
data=[9, 8, 7, 2, 1, 3, 6, 4, 0, 5]
print(data)
h=[]
for x in data:
    heap.insert(h,x)
    # print(h)
    heap.print_heap(h)
print("===")
last = len(h)-1
h.extend([-15,-16,-17,-18])
print(h)
for i in range(len(h)):
    print(heap.pop(h,last), h)
    last -=1
    # print(heap.print_heap(h))