public static void add(Node n) { if (root == null) { root = n; } else { root.add(n); } }
public void add(Node n) { if (n == null) { return; } if (value > n.value) { if (left == null) { left = n; } else { left.add(n); } } else { if (right == null) { right = n; } else { right.add(n); } } if (RightHeight - LeftHeight > 1) { LeftRotate(); } if (LeftHeight - RightHeight > 1) { RightRotate(); } //左旋和右旋并不能使树达到平衡的状态,还需要使用双旋 }