Created
May 16, 2017 17:33
-
-
Save lironsade/8f6a2c7f2bf48bb73458edff0a7491de 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment