Currently doing the exercise on min-heaps and we are trying to switch parent and child value if parent s bigger. I : don’t understand the before last sentence: idx = self.parent_idx(idx) Thank you in advance!
def heapify_up(self):
print("Heapifying up")
idx = self.count
while self.parent_idx(idx) > 0:
child = self.heap_list[idx]
parent = self.heap_list[self.parent_idx(idx)]
if parent > child:
print("swapping {0} with {1}".format(parent, child))
self.heap_list[idx] = parent
self.heap_list[self.parent_idx(idx)] = child
idx = self.parent_idx(idx)
print("Heap Restored {0}".format(self.heap_list))