赞
踩
一棵AVL树或者是空树,或者是具有下列性质的二叉搜索树:
结点的平衡因子 balance(balance factor)
class AVLNode{ private AVLNode leftChild; private AVLNode parent; private AVLNode rightChild; private int data; private int balance; public AVLNode(){ leftChild = null; parent = null; rightChild = null; data = 0; } public AVLNode(int data){ leftChild = null; parent = null; rightChild = null; this.data = data; } public AVLNode(int data,AVLNode parent){ leftChild = null; this.parent = parent; rightChild = null; this.data = data; } public AVLNode(int data,AVLNode parent,AVLNode leftChild,AVLNode rightChild){ this.leftChild = leftChild; this.parent = parent; this.rightChild = rightChild; this.data = data; } } private AVLNode head; //指向根节点 private int curSize; //记录有效个数 public AVLTree(){ curSize = 0; head = new AVLNode(); }
示例:
/**
* 左单旋转
* @param ptr
*/
private void
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。