def __percolate_up(self, node: BinaryNode) -> None: """ Trickle down heap operation """ if node.parent and node.parent.value > node.value: node.value, node.parent.value = node.parent.value, node.value self.__percolate_up(node.parent)
def __percolate_down(self, node: BinaryNode) -> None: """ Bubble up heap operation """ min_child = node.get_min_child() if min_child and min_child.value < node.value: node.value, min_child.value = min_child.value, node.value self.__percolate_down(min_child)