Created
February 10, 2018 17:52
-
-
Save tarlanahad/b59d2a16e99c08c7adb1bc407fc6b3eb 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 ReBalance(Node node) { | |
if (height(node.Left) - height(node.Right) > 1) {//if the problem in the left subtree | |
if (height(node.Left.Left) > height(node.Left.Right)) //if the problem in the left subtree | |
node = RightRotate(node);//do right subtree | |
else | |
node = LeftRightRotate(node); | |
} else { | |
if (height(node.Right.Left) > height(node.Right.Right)) | |
node = LeftRotate(node); | |
else | |
node = RightLeftRotate(node); | |
} | |
if (node.Parent == null)//if the current node is root | |
Root = node;//adjust the root | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment