Exemplo n.º 1
0
    def insert(self, value):
        tree = BinomialTreeNode(value)
        tree.marked = False

        self.trees.append(tree)

        # Update the min node reference if needed
        if self.min_tree is None or self.min_tree.value.value > value:
            self.min_tree = self.trees.get_tail_node()
Exemplo n.º 2
0
    def insert(self, value):
        tree = BinomialTreeNode(value)
        tree.marked = False

        self.trees.append(tree)

        # Update the min node reference if needed
        if self.min_tree is None or self.min_tree.value.value > value:
            self.min_tree = self.trees.get_tail_node()
Exemplo n.º 3
0
 def insert(self, value):
     """
     Insert a value onto the heap
     Merges this heap with a new heap with only one node
     """
     # Create a heap with a single node
     new_heap = BinomialHeap()
     new_heap.trees.head.value = BinomialTreeNode(value)
     new_heap.min_tree = new_heap.trees.head
     # Merge it with the current heap
     self.merge(new_heap)
Exemplo n.º 4
0
    def decrease_min(self, node: BinomialTreeNode, value):
        if node.value < value:
            raise ValueError('Value should be smaller than this value')

        parent = node.parent

        while parent:

            # Remove node from parent and add it to the tree list
            parent.children.remove(node)
            node.parent = None
            self.trees.append(node)
            node.marked = False

            if self.min_tree is None or self.min_tree.value > node.value:
                self.min_tree = self.trees.get_tail_node()

            # Mark the parent
            if parent.marked:
                pass
Exemplo n.º 5
0
    def decrease_min(self, node: BinomialTreeNode, value):
        if node.value < value:
            raise ValueError('Value should be smaller than this value')

        parent = node.parent

        while parent:

            # Remove node from parent and add it to the tree list
            parent.children.remove(node)
            node.parent = None
            self.trees.append(node)
            node.marked = False

            if self.min_tree is None or self.min_tree.value > node.value:
                self.min_tree = self.trees.get_tail_node()

            # Mark the parent
            if parent.marked:
                pass