Skip to content

Instantly share code, notes, and snippets.

@sarahzhao25
Created January 9, 2018 05:39
Show Gist options
  • Save sarahzhao25/41c26587c000a5f9393fbe6db73f363d to your computer and use it in GitHub Desktop.
Save sarahzhao25/41c26587c000a5f9393fbe6db73f363d to your computer and use it in GitHub Desktop.
function rightRotate(root) {
let pivot = root.left;
if (pivot.right) {
//establish right to be child of root's parent.
pivot.right.parent.node = root;
pivot.right.parent.side = 'left';
}
root.left = pivot.right;
pivot.parent.node = root.parent.node;
(root.parent.node) ? root.parent.node[root.parent.side] = pivot: pivot.parent.side = '';
root.parent.node = pivot;
root.parent.side = 'right';
pivot.right = root;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment