Skip to content

Commit

Permalink
added heap
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkCode01 committed Aug 2, 2021
1 parent afa7b22 commit 26de1b5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions heap/heap.py
@@ -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)

0 comments on commit 26de1b5

Please sign in to comment.