/// <summary>
    /// Removes the highest priority value from this priority queue.
    /// </summary>
    /// <remarks>
    /// Complexity: O(log n)
    /// </remarks>
    public void DequeueMax()
    {
        if ((null == m_MinHeap) || (null == m_MinHeap))
        {
            return;
        }

        //-- Remove the top node of the hi-to-lo heap
        BinomialTreeNode <PriorityQueueTuple> removedNode = m_MaxHeap.Pop();

        if (null == removedNode)
        {
            //-- Heap is empty
            return;
        }

        //-- Remove the matching node from the min heap
        m_MinHeap.RemoveNode(removedNode.Counterpart);
    }
    /// <summary>
    /// Remove the specified node from this heap.
    /// </summary>
    /// <remarks>
    /// Complexity: O(log n)
    /// </remarks>
    /// <param name="node"></param>
    public void RemoveNode(BinomialTreeNode <T> node)
    {
        BinomialTreeNode <T> parentNode = node.Parent;

        //-- Bubble the node to the top of the heap
        while (null != node.Parent)
        {
            //-- Swap the value with the parent
            T tempValue = parentNode.Value;
            parentNode.m_Value = node.Value;
            node.m_Value       = tempValue;

            //-- Swap the counterparts with the parent
            node.m_Counterpart.m_Counterpart       = parentNode;
            parentNode.m_Counterpart.m_Counterpart = node;

            BinomialTreeNode <T> tempCounterpart = parentNode.Counterpart;
            parentNode.m_Counterpart = node.Counterpart;
            node.m_Counterpart       = tempCounterpart;

            //-- Move to the parent
            node       = parentNode;
            parentNode = node.Parent;
        }

        //-- Find the tree the root node belongs to
        LinkedListNode <BinomialTree <T> > treeIter = m_Trees.First;

        while (null != treeIter)
        {
            if (treeIter.Value.Root == node)
            {
                //-- Matching root node found; remove from heap
                RemoveRootNode(treeIter);
                break;
            }

            treeIter = treeIter.Next;
        }
    }
    /// <summary>
    /// Adds a specified binomial tree of the same order as a
    /// sub-tree of this one by adding its root node as a child of
    /// this tree's root node.
    /// </summary>
    /// <remarks>
    /// Complexity: O(1)
    /// </remarks>
    /// <param name="other">Tree to add.</param>
    /// <returns>The resulting tree (this tree).</returns>
    public BinomialTree <T> AddSubTree(BinomialTree <T> other)
    {
        if (m_Order != other.m_Order)
        {
            //-- Only merge binomial trees of the same order
            return(this);
        }

        //-- Add the other tree's root as a child of our own
        if (null != m_Root)
        {
            other.Root.m_Parent = m_Root;
            m_Root.Children.Append(other.Root);
        }
        else
        {
            m_Root = other.Root;
        }

        //-- Our binomial tree is now one level "deeper"
        ++m_Order;

        return(this);
    }
 public int CompareTo(BinomialTreeNode <T> other)
 {
     return(m_Value.CompareTo(other.m_Value));
 }
 public BinomialTree(BinomialTreeNode <T> rootNode)
 {
     m_Root  = rootNode;
     m_Order = 0;
 }
 public BinomialTree(T rootValue)
 {
     m_Root  = new BinomialTreeNode <T>(rootValue);
     m_Order = 0;
 }
 public BinomialTree()
 {
     m_Root  = null;
     m_Order = -1;
 }