File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 5
5
class MaxHeap :
6
6
def __init__ (self , items = []):
7
7
super ().__init__ ()
8
- self .heap = [ 0 ]
8
+ self .heap = None
9
9
for i in items :
10
10
self .heap .append (i )
11
11
self .__floatUp (len (self .heap ) - 1 )
@@ -18,18 +18,18 @@ def peek(self):
18
18
if self .heap [1 ]:
19
19
return self .heap [1 ]
20
20
else :
21
- return False
21
+ return None
22
22
23
23
def pop (self ):
24
24
if len (self .heap ) > 2 :
25
25
self .__swap (1 , len (self .heap ) - 1 )
26
- max = self .heap .pop ()
26
+ max1 = self .heap .pop ()
27
27
self .__bubbleDown (1 )
28
28
elif len (self .heap ) == 2 :
29
- max = self .heap .pop ()
29
+ max1 = self .heap .pop ()
30
30
else :
31
- max = False
32
- return max
31
+ max1 = None
32
+ return max1
33
33
34
34
def __swap (self , i , j ):
35
35
self .heap [i ], self .heap [j ] = self .heap [j ], self .heap [i ]
@@ -57,4 +57,4 @@ def __bubbleDown(self, index):
57
57
m = MaxHeap ([95 , 3 , 21 ])
58
58
m .push (10 )
59
59
print (str (m .heap [0 :len (m .heap )]))
60
- print (str (m .pop ()))
60
+ print (str (m .pop ()))
You can’t perform that action at this time.
0 commit comments