Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Node {
- public int val = 0;
- public Node left = null;
- public Node right = null;
- public int leftHeight = 0;
- public int rightHeight = 0;
- }
- public class AVLTree {
- public int outBalance = 3;
- public Node root = null;
- public Node badBalance = null;
- public void insert (Node current = root) {
- if (null != current) {
- if (current.val < this.val) {
- current.right += 1;
- if (Math.abs(current.right - current.left) == outBalance) {
- badBalance = current;
- }
- if (null != current.right) {
- insert(current.right);
- } else {
- current.right = this;
- if (null != outBalance) {
- outBalance = null:
- current.left += 1;
- if (Math.abs(current.left - current.right) == outBalance) {
- badBalance = current;
- }
- if (null != current.left) {
- insert(current.left);
- } else {
- current.left = this;
- if (null != outBalance) {
- outBalance = null:
- //rotate current
- }
- }
- }
- } else {
- root = this;
- }
- }
- public class AVL {
- public static void main(String[] args) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement