Beispiel #1
0
        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);
        }
Beispiel #2
0
 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));
     }
 }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        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++;
        }