Last active
May 17, 2017 10:25
-
-
Save lironsade/d6e7c4e3f0058708cdb8c034fc65000a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void rotateLeft(Node rotated) { | |
Node rotator = rotated.getRight(); | |
rotator.setDad(rotated.getDad()); | |
rotated.setRight(rotator.getLeft()); | |
rotator.setLeft(rotated); | |
if(rotator.getDad() != null){ | |
if (rotator.getDad().getRight() == rotated){ | |
rotator.getDad().setRight(rotator); | |
} else { | |
rotator.getDad().setLeft(rotator); | |
} | |
} else{ | |
this.setRoot(rotator); | |
} | |
} | |
private void rotateRight(Node rotated) { | |
Node rotator = rotated.getLeft(); | |
rotator.setDad(rotated.getDad()); | |
rotated.setLeft(rotator.getRight()); | |
rotator.setRight(rotated); | |
if (rotator.getDad() != null) { | |
if (rotator.getDad().getLeft() == rotated) { | |
rotator.getDad().setLeft(rotator); | |
} else { | |
rotator.getDad().setRight(rotator); | |
} | |
} else { | |
this.setRoot(rotator); | |
} | |
} | |
void setLeft(Node left) { | |
this.left = left; | |
if (left != null) { | |
this.left.setDad(this); | |
this.leftHeight = left.getHeight(); | |
} else { | |
this.leftHeight = -1; | |
} | |
} | |
void setRight(Node right) { | |
this.right = right; | |
if (right != null) { | |
this.right.setDad(this); | |
this.rightHeight = right.getHeight(); | |
} else { | |
this.rightHeight = -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment