Zuo (leftist heaps) is also known as the Zoo, left-leaning heap. Zuo as a heap, preserving some of the properties of the heap.
1th, the left-hand pile is still constructed in the form of a two-fork tree;
2nd, the value of any node in the left-hand heap is smaller than the arbitrary node value of its subtree (minimum heap characteristics). However, unlike the general two-fork heap, the left-hand heap is no longer a complete binary tree, and it is a very unbalanced tree.
Package com.wpr.collection;/** * Left heap: Two fork heap disadvantage, first, only the smallest element can be found; second, the operation of merging two heaps is cumbersome * Note: All advanced data structures that support effective merging require the use of chained data structures * * Definition: 0 path Long (null path length) NPL represents the length of the shortest path from node x to a node that does not have two sons * @author WPR * */public class Leftheap<anytype extends Compa rable<? Super anytype>> {private node<anytype> root;public leftheap () {root = null;} private static class Node<anytype> {AnyType element; Node<anytype> left; Node<anytype> right;int npl;public Node (AnyType Element) {this (element,null,null);} Public Node (AnyType element, node<anytype> left, node<anytype> right) {this.element = Element;this.left = Lef T;this.right = RIGHT;THIS.NPL = 0;}} /** * @param x */public void Merge (Leftheap<anytype> x) {if (this = = x) return; root = merge (Root,x.root);} /** * Insert a new element * @param x */public void Insert (AnyType x) {root = Merge (new node<anytype> (x), root);} /** * Delete Minimum element * @return */public AnyType deletemin () {if (root = null) return null; AnyType item = root.element;root = Merge (Root.leFt,root.right); return item;} /** * Merges the H1 and H2 two heaps, returning the root node (implemented recursively) * @param H1 * @param h2 * @return */private node<anytype> Merge (node<anytype> H1, node<anytype> H2) {if (H1 = = null) return h2;if (H2 = null) return H1;if (H1.element.compareTo (h2.element) <0) { H1My collection frame sixth bullet left-hand heap