// Merge two subtrees together, returning the one that came out on top. // For a pairing heap, merging consists of adding the larger node // to the sub list of the smaller. private HeapNode <T> merge(HeapNode <T> a, HeapNode <T> b) { if (compare(a.getNode(), b.getNode()) <= 0) // a <= b (swap a and b) { HeapNode <T> tmp = a; a = b; b = tmp; } // Here we assume that a > b, therefore a is added to b's children // Remove a from any child list it might be in. a.extract(); // Link a into b's child list b.addChild(a); return(b); }