Created
January 9, 2018 05:39
-
-
Save sarahzhao25/41c26587c000a5f9393fbe6db73f363d 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
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