-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP2.py
More file actions
49 lines (32 loc) · 778 Bytes
/
P2.py
File metadata and controls
49 lines (32 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from json import load
from PyQt5 import *
from PyQt5.QtWidgets import *
from PyQt5.QtQuickWidgets import *
A=[]
class heap():
heapSize=0
def __init__(self,heapsize):
self.heapSize=heapsize
def left(i):
return 2*i
def right(i):
return 2*i+1
def MaxHeapify(A,i):
l=left(i)
r=right(i)
if l<A.heapSize and A[l]<=A[r]:
largest=l
else:
largest=i
if r<A.heapSize and A[r]<=A[largest]:
largest=r
if r != i:
largest=i
temp=A[i]
A[i]=A[largest]
A[largest]=temp
MaxHeapify(A,largest)
def Build_Max_Heap(A):
A.heapSize=A.length
for i in reversed(range(2,int(len(A)/2))):
MaxHeapify(A,i)