public FibonacciHeapNode <TE, TP> GetMinimumNodeAmongSibglings() { FibonacciHeapNode <TE, TP> minimumNode = this; // Find minimum FibonacciHeapNode <TE, TP> leftIterator = LeftSibling; FibonacciHeapNode <TE, TP> rightIterator = RightSibling; // Look for a smaller node on the left while (leftIterator != null) { if (leftIterator.IsSmallerThan(minimumNode)) { minimumNode = leftIterator; } leftIterator = leftIterator.LeftSibling; } // Look for a smaller node on the right while (rightIterator != null) { if (rightIterator.IsSmallerThan(minimumNode)) { minimumNode = rightIterator; } rightIterator = rightIterator.RightSibling; } // Done return smallest node found return(minimumNode); }
private FibonacciHeapNode <TE, TP> MergeHeaps(FibonacciHeapNode <TE, TP> heap1, FibonacciHeapNode <TE, TP> heap2) { if (heap1.IsSmallerThan(heap2)) { return(MergeInto(heap1, heap2)); } else { return(MergeInto(heap2, heap1)); } }
public void DecreaseKey(TE element, TP priority) { FibonacciHeapNode <TE, TP> node = GetNode(element); node.Priority = priority; // If the heap order is violated, extract the subtree and move it to the main tree list if (node.Parent != null && node.IsSmallerThan(node.Parent)) { ExtractTree(node); } Root = Root.GetMinimumNodeAmongSibglings(); }
public void Insert(TE element, TP priority) { var newNode = new FibonacciHeapNode <TE, TP>(element, priority); if (Empty) { Root = newNode; } else { Append(Root, newNode); if (newNode.IsSmallerThan(Root)) { Root = newNode; } } Count++; }