左式堆
来源:互联网 发布:数据机房空调设计 编辑:程序博客网 时间:2024/06/06 02:40
package com.iflytek.heap;/** * 左式堆 * @author fgtian * */public class LeftListHeap {public static class HeapNode {int mValue;int mNpl = 0;HeapNode mLeftChild;HeapNode mRightChild;}HeapNode mRoot = null;public void insert(int value) {HeapNode node = new HeapNode();node.mValue = value;merge(node);}public int delMin() {if (null == mRoot) {throw new NullPointerException("null == mRoot");}int value = mRoot.mValue;mRoot = merge(mRoot.mLeftChild, mRoot.mRightChild);return value;}public void merge(HeapNode node) {mRoot = merge(mRoot, node);if (npl(mRoot.mRightChild) > npl(mRoot.mLeftChild)) {HeapNode l = mRoot.mLeftChild;mRoot.mLeftChild = mRoot.mRightChild;mRoot.mRightChild = l;}mRoot.mNpl = Math.min(npl(mRoot.mLeftChild), npl(mRoot.mRightChild)) + 1;}public void merge(LeftListHeap heap) {merge(heap.mRoot);}public static int npl(HeapNode h) {if (null == h) {return -1;}return h.mNpl;}public static HeapNode merge(HeapNode h1, HeapNode h2) {if (null == h1) {return h2;} else if (h2 == null) {return h1;} else { // 两个都不是nullint v1 = h1.mValue;int v2 = h2.mValue;if (v1 <= v2) { // 拿他的h1.mRightChild = merge(h1.mRightChild, h2);if (npl(h1.mLeftChild) < npl(h1.mRightChild)) {HeapNode node = h1.mLeftChild;h1.mLeftChild = h1.mRightChild;h1.mRightChild = node;}h1.mNpl = Math.min(npl(h1.mLeftChild), npl(h1.mRightChild)) + 1;return h1;} else {h2.mRightChild = merge(h1, h2.mRightChild);if (npl(h2.mLeftChild) < npl(h2.mRightChild)) {HeapNode node = h2.mLeftChild;h2.mLeftChild = h2.mRightChild;h2.mRightChild = node;}h2.mNpl = Math.min(npl(h2.mLeftChild), npl(h2.mRightChild)) + 1;return h2;}}}}
2 1
- 左式堆
- 左式堆
- 左式堆
- 左式堆
- 左式堆
- 左式堆
- 左式堆
- 什么是左式堆
- 左式堆学习
- 左式堆decreaseKey
- 数据结构-左式堆
- 左式堆(优先队列)
- 左式堆的实现
- 左式堆 斜堆
- 左式堆合并的实现
- 左式堆的deletdMin例程
- 左式堆的基本操作
- 左式堆--C语言实现
- LeetCode:Binary Tree Preorder Traversal
- 数据库命令和连接mysql服务器
- 正则表达式第四篇(Java中使用正则表达式)
- service-application-struts相关的配置
- 'mysql' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
- 左式堆
- 调用带参数的线程Thread
- 探cocos2dx裁剪结点、拖尾效果、进度效果、渲染纹理实现(misc_nodes),源码版本(2.2.3)
- [Sqlite]-->数据迁移备份--从低版本3.6.2到高版本3.8.6
- 1019. General Palindromic Number (20)
- 多线程中condition wait
- appsecusa 2014
- 我的多年编程经验总结
- 相关的类