We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5e4945a commit 9cd42e2Copy full SHA for 9cd42e2
1 file changed
sort/heap_sort.py
@@ -2,7 +2,13 @@ def heap_sort(arr):
2
""" Heapsort
3
Complexity: O(n log(n))
4
"""
5
- pass
+
6
+ for i in range(len(arr)-1,-1,-1):
7
+ heapify(arr, i)
8
9
+ temp = arr[0]
10
+ arr[0] = arr[i]
11
+ arr[i] = temp
12
13
14
def heapify(arr, end):
@@ -41,9 +47,10 @@ def heapify(arr, end):
41
47
heapify(array, end)
42
48
for i in range(0, int((end-1)/2)+1):
43
49
if array[i] < array[2*i+1]:
50
+ is_heap = False
44
51
if 2*i + 2 <= end and array[i] < array[2*i + 2]:
45
52
is_heap = False
46
53
print(array)
54
print(is_heap)
-# heap_sort(array)
-# print(array)
55
+heap_sort(array)
56
+print(array)
0 commit comments