平衡二叉树
平衡二叉树规则:每个节点左右孩子高度差不大于1 package newcoder; /** * 平衡二叉树*/ public class AVLTree<T extends Comparable<T>> { private AVLTreeNode<T> mRoot; // 根结点 // 节点数据结构 class AVLTreeNode<T extends Comparable<T>> { T key; int height; AVLTreeNode<T> left; AVLTreeNode<T> right; public AVLTreeNode(T key, AVLTreeNode<T> left, AVLTreeNode<T> right) { this.key = key; this.left = left; this.right = right; this.height = 0; } } public AVLTree() { mRoot = null; } /* * 获取树的高度 */ private int height(AVLTreeNode<T> tree) { if (tree != null) return tree.height; return 0; } public int height() { return height(mRoot); } /* *