Skip to content

Instantly share code, notes, and snippets.

@sarahzhao25
Last active January 9, 2018 05:40
Show Gist options
  • Save sarahzhao25/98821a090fa9726f6083eaece757dd18 to your computer and use it in GitHub Desktop.
Save sarahzhao25/98821a090fa9726f6083eaece757dd18 to your computer and use it in GitHub Desktop.
function rotate(root) {
if (root.balanceFactor() > 1) {
if (root.left.balanceFactor() === -1) leftRotate(root.left);
rightRotate(root);
}
else if (root.balanceFactor() < -1) {
if (root.right.balanceFactor() === 1) rightRotate(root.right);
leftRotate(root);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment