Created
February 10, 2018 17:11
-
-
Save tarlanahad/803d60530d7bbb294f57483edd273bb4 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 addHelper(Node parentPosition, Node newNode) { | |
if (newNode.Key > parentPosition.Key) {// newNode's key is greater | |
//than that of parent node go right | |
if (parentPosition.Right == null) {//If the node is leaf | |
parentPosition.Right = newNode;//append newNode to its Right | |
newNode.Parent = parentPosition;//newNode's parent | |
CurrentSize++;//increment tree's size | |
} else { | |
addHelper(parentPosition.Right, newNode);//If it is not a leaf | |
} //go down | |
} else { | |
if (parentPosition.Left == null) { | |
parentPosition.Left = newNode; | |
newNode.Parent = parentPosition; | |
CurrentSize++; | |
} else { | |
addHelper(parentPosition.Left, newNode); | |
} | |
} | |
CheckBalance(newNode);//Check the balance between children | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment