public static Heap DeleteMin(Heap h) { if (IsEmpty(h)) { throw new ArgumentNullException(nameof(h)); } if (PrimH.IsEmpty(h.P)) { return(Empty); } var p1 = PrimH.FindMin(h.P); var p2 = PrimH.DeleteMin(h.P); return(new Heap(p1.X, PrimH.Merge(p1.P, p2))); }
public static Heap Merge(Heap h1, Heap h2) { if (IsEmpty(h1)) { return(h2); } if (IsEmpty(h2)) { return(h1); } if (h1.X.CompareTo(h2.X) <= 0) { return(new Heap(h1.X, PrimH.Insert(h2, h1.P))); } return(new Heap(h2.X, PrimH.Insert(h1, h2.P))); }