Skip to content

Commit 302fa89

Browse files
committed
Heaps
1 parent 2c4404f commit 302fa89

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

PQ & Heap/HeapSort.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from Heaps import Heap
2+
3+
def heapsort(A):
4+
H = Heap()
5+
n = len(A)
6+
for i in range(n):
7+
H.insert(A[i])
8+
k = n-1
9+
for i in range(H._csize):
10+
A[k] = H.deletemax()
11+
k = k - 1
12+
13+
14+
A = [63, 250, 835, 947, 651, 28]
15+
print('Original Array:',A)
16+
heapsort(A)
17+
print('Sorted Array:',A)
18+
19+

0 commit comments

Comments
 (0)