Exemple #1
0
        /// <summary>
        ///     union
        /// </summary>
        /// <param name="heap"></param>
        public void Union(MinFibonacciHeap <K, V> heap)
        {
            MinFibonacciHeap <K, V> h = Union(this, heap);

            Count   = h.Count;
            minRoot = h.minRoot;
        }
Exemple #2
0
        /// <summary>
        ///     union
        ///     It runs at O(1)
        /// </summary>
        /// <param name="h1"></param>
        /// <param name="h2"></param>
        /// <returns></returns>
        public static MinFibonacciHeap <K, V> Union(MinFibonacciHeap <K, V> h1, MinFibonacciHeap <K, V> h2)
        {
            if (h1 == null || h1.minRoot == null)
            {
                return(h2);
            }
            if (h2 == null || h2.minRoot == null)
            {
                return(h1);
            }

            var heap = new MinFibonacciHeap <K, V>();

            heap.minRoot = h1.minRoot;
            if (h1.minRoot.Key.CompareTo(h2.minRoot.Key) > 0)
            {
                heap.minRoot = h2.minRoot;
            }

            //concatenate the root list of H1 and H2
            FibonacciHeapNode <K, V> h1Node = h1.minRoot.RightSibling;
            FibonacciHeapNode <K, V> h2Node = h2.minRoot.RightSibling;

            h1.minRoot.RightSibling = h2Node;
            h2Node.LeftSibling      = h1.minRoot;
            h2.minRoot.RightSibling = h1Node;
            h1Node.LeftSibling      = h2.minRoot;

            heap.Count = h1.Count + h2.Count;
            return(heap);
        }