Advertisement
kimo12

Untitled

Mar 23rd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1.     private void deleteRebalance(Node<T> t) {
  2.         Node<T> parent = null; // up
  3.         Node<T> check = t;
  4.         Node<T> child = t;
  5.         while (check.hasParent()) {
  6.             check = (Node<T>) check.getParent();
  7.             int balanceFactor = check.getBalanceFactor();
  8.             if (balanceFactor == 2) {
  9.                 if (check.getParent() != null)
  10.                     parent = (Node<T>) check.getParent();
  11.                 if (check.hasLeftChild()) {
  12.                     int leftChildBF = ((Node) check.getLeftChild()).getBalanceFactor();
  13.                     if (leftChildBF == 1) {
  14.                         child =(Node<T>) check.getLeftChild();
  15.                         leftLeft(check, child, parent);
  16.                     }
  17.                 } else if (check.hasRightChild()) {
  18.                     int rightChildBF = ((Node) check.getLeftChild()).getBalanceFactor();
  19.                     if (rightChildBF == -1) {
  20.                         child =(Node<T>) check.getRightChild();
  21.                         leftRight(check, child, parent);
  22.                     }
  23.                 }
  24.             } else if (balanceFactor == -2) {
  25.                 if (check.getParent() != null)
  26.                     parent = (Node<T>) check.getParent();
  27.                 if (check.hasLeftChild()) {
  28.                     int leftChildBF = ((Node) check.getLeftChild()).getBalanceFactor();
  29.                     if (leftChildBF == -1) {
  30.                         child =(Node<T>) check.getRightChild();
  31.                         rightRight(check, child, parent);
  32.                     }
  33.                 } else if (check.hasRightChild()) {
  34.                     int rightChildBF = ((Node) check.getLeftChild()).getBalanceFactor();
  35.                     if (rightChildBF == 1) {
  36.                         child =(Node<T>) check.getLeftChild();
  37.                         rightLeft(check, child, parent);
  38.                     }
  39.                 }
  40.             }
  41.         }
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement