File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -24,14 +24,14 @@ def insert(self, item):
24
24
def _bubbleUp (self , currentPosition ):
25
25
if currentPosition >= 1 : # no need to do bubbleUp for 1 element
26
26
index = currentPosition
27
- parrentIndex = index // 2
27
+ parentIndex = ( index - 1 ) // 2
28
28
29
- if parrentIndex >= 0 and self .heap [parrentIndex ] < self .heap [index ]:
30
- self ._swap (parrentIndex , index )
31
- self ._bubbleUp (parrentIndex )
29
+ if parentIndex >= 0 and self .heap [parentIndex ] < self .heap [index ]:
30
+ self ._swap (parentIndex , index )
31
+ self ._bubbleUp (parentIndex )
32
32
33
33
def peek (self ):
34
- return self .heap [0 ] if self .heap else False
34
+ return self .heap [0 ] if self .heap else None
35
35
36
36
def pop (self ):
37
37
element = self .peek ()
@@ -42,7 +42,7 @@ def pop(self):
42
42
return element
43
43
44
44
def _bubbleDown (self , index ):
45
- leftChildIndex = 2 * index + 1
45
+ leftChildIndex = 2 * index + 1
46
46
rightChildIndex = 2 * index + 2
47
47
largest = index
48
48
if len (self .heap ) > leftChildIndex and self .heap [largest ] < self .heap [leftChildIndex ]:
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ def test(self):
21
21
ob .pop ()
22
22
ob .pop ()
23
23
ob .pop ()
24
- self .assertEqual (ob .peek (), False , msg = "Max Element is not matched" )
24
+ self .assertEqual (ob .peek (), None , msg = "Max Element is not matched" )
25
25
26
26
if __name__ == '__main__' :
27
27
unittest .main ()
You can’t perform that action at this time.
0 commit comments