Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void deleteRebalance(Node<T> t) {
- Node<T> parent = null; // up
- Node<T> check = t;
- Node<T> child = t;
- while (check.hasParent()) {
- check = (Node<T>) check.getParent();
- int balanceFactor = check.getBalanceFactor();
- if (balanceFactor == 2) {
- if (check.getParent() != null)
- parent = (Node<T>) check.getParent();
- if (check.hasLeftChild()) {
- int leftChildBF = ((Node) check.getLeftChild()).getBalanceFactor();
- if (leftChildBF == 1) {
- child =(Node<T>) check.getLeftChild();
- leftLeft(check, child, parent);
- }
- } else if (check.hasRightChild()) {
- int rightChildBF = ((Node) check.getLeftChild()).getBalanceFactor();
- if (rightChildBF == -1) {
- child =(Node<T>) check.getRightChild();
- leftRight(check, child, parent);
- }
- }
- } else if (balanceFactor == -2) {
- if (check.getParent() != null)
- parent = (Node<T>) check.getParent();
- if (check.hasLeftChild()) {
- int leftChildBF = ((Node) check.getLeftChild()).getBalanceFactor();
- if (leftChildBF == -1) {
- child =(Node<T>) check.getRightChild();
- rightRight(check, child, parent);
- }
- } else if (check.hasRightChild()) {
- int rightChildBF = ((Node) check.getLeftChild()).getBalanceFactor();
- if (rightChildBF == 1) {
- child =(Node<T>) check.getLeftChild();
- rightLeft(check, child, parent);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement