Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afa7b22
commit 26de1b5
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class MinHeap: | ||
def __init__(self): | ||
self.heap = [] | ||
self.heap_size = 0 | ||
|
||
def getParentNodeIndex(self, i: int): | ||
return (i - 1) // 2 | ||
|
||
def getLeftChildNodeIndex(self, i: int): | ||
return 2 * i + 1 | ||
|
||
def getRightChildNodeIndex(self, i: int): | ||
2 * i + 2 | ||
|
||
def hasParent(self, i: int) -> bool: | ||
return self.getParentNodeIndex(i) < len(self.heap) | ||
|
||
def hasLeftChild(self, i: int) -> bool: | ||
return self.getLeftChildNodeIndex(i) < len(self.heap) | ||
|
||
def hasRigthChild(self, i: int) -> bool: | ||
return self.getRightChildNodeIndex(i) < len(self.heap) | ||
|
||
def getMinValue(self) -> int: | ||
return self.heap[0] | ||
|
||
def printAll(self): | ||
print(self.heap) | ||
|