File tree 1 file changed +7
-6
lines changed
1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change 7
7
except NameError :
8
8
raw_input = input # Python 3
9
9
10
+ #This heap class start from here.
10
11
class Heap :
11
- def __init__ (self ):
12
+ def __init__ (self ): #Default constructor of heap class.
12
13
self .h = []
13
14
self .currsize = 0
14
15
@@ -37,13 +38,13 @@ def maxHeapify(self,node):
37
38
self .h [m ] = temp
38
39
self .maxHeapify (m )
39
40
40
- def buildHeap (self ,a ):
41
+ def buildHeap (self ,a ): #This function is used to build the heap from the data container 'a'.
41
42
self .currsize = len (a )
42
43
self .h = list (a )
43
44
for i in range (self .currsize // 2 ,- 1 ,- 1 ):
44
45
self .maxHeapify (i )
45
46
46
- def getMax (self ):
47
+ def getMax (self ): #This function is used to get maximum value from the heap.
47
48
if self .currsize >= 1 :
48
49
me = self .h [0 ]
49
50
temp = self .h [0 ]
@@ -54,7 +55,7 @@ def getMax(self):
54
55
return me
55
56
return None
56
57
57
- def heapSort (self ):
58
+ def heapSort (self ): #This function is used to sort the heap.
58
59
size = self .currsize
59
60
while self .currsize - 1 >= 0 :
60
61
temp = self .h [0 ]
@@ -64,7 +65,7 @@ def heapSort(self):
64
65
self .maxHeapify (0 )
65
66
self .currsize = size
66
67
67
- def insert (self ,data ):
68
+ def insert (self ,data ): #This function is used to insert data in the heap.
68
69
self .h .append (data )
69
70
curr = self .currsize
70
71
self .currsize += 1
@@ -74,7 +75,7 @@ def insert(self,data):
74
75
self .h [curr ] = temp
75
76
curr = curr / 2
76
77
77
- def display (self ):
78
+ def display (self ): #This function is used to print the heap.
78
79
print (self .h )
79
80
80
81
def main ():
You can’t perform that action at this time.
0 commit comments