protected LeftistHeap(Func <T, T, int> comparer, int height, T item, ILeftistHeap <T> left, ILeftistHeap <T> right)
 {
     this.Comparer = comparer;
     this.Height   = height;
     this.Item     = item;
     this.Left     = left;
     this.Right    = right;
 }
    private static IEnumerator <T> CreateEnumerator(ILeftistHeap <T> heap)
    {
        while (!heap.IsEmpty)
        {
            yield return(heap.Item);

            heap = heap.Delete();
        }
    }
 private static ILeftistHeap <T> Balance(T item, Func <T, T, int> comparer, ILeftistHeap <T> a, ILeftistHeap <T> b)
 {
     if (a.Height >= b.Height)
     {
         return(new LeftistHeap <T>(comparer, b.Height + 1, item, a, b));
     }
     else
     {
         return(new LeftistHeap <T>(comparer, a.Height + 1, item, b, a));
     }
 }
 public static ILeftistHeap <T> Merge(ILeftistHeap <T> x, ILeftistHeap <T> y)
 {
     if (x.IsEmpty)
     {
         return(y);
     }
     else if (y.IsEmpty)
     {
         return(x);
     }
     else
     {
         Func <T, T, int> comparer = x.Comparer;
         if (comparer(x.Item, y.Item) <= 0)
         {
             return(Balance(x.Item, comparer, x.Left, Merge(x.Right, y)));
         }
         else
         {
             return(Balance(y.Item, comparer, y.Left, Merge(x, y.Right)));
         }
     }
 }