My collection frame sixth bullet left-hand heap

Source: Internet
Author: User

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) { H1

My collection frame sixth bullet left-hand heap

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.