public static void Main(System.String[] args) { int numItems = 100; LeftistHeap h = new LeftistHeap(); LeftistHeap h1 = new LeftistHeap(); int i = 37; for (i = 37; i != 0; i = (i + 37) % numItems) { if (i % 2 == 0) { h1.insert(new MyInteger(i)); } else { h.insert(new MyInteger(i)); } } h.merge(h1); for (i = 1; i < numItems; i++) { if (((MyInteger)(h.deleteMin())).intValue() != i) { System.Console.Out.WriteLine("Oops! " + i); } } }
/// <summary> Merge rhs into the priority queue. /// rhs becomes empty. rhs must be different from this. /// </summary> /// <param name="rhs">the other leftist heap. /// </param> public virtual void merge(LeftistHeap rhs) { if (this == rhs) { // Avoid aliasing problems return; } root = merge(root, rhs.root); rhs.root = null; }