Binary Search Tree : Insertion
https://www.hackerrank.com/challenges/binary-search-tree-insertion/problem
Node * insert(Node * root, int value) {
Node * newNode = new Node(value);
// newNode->data = value;
newNode->left = NULL;
newNode->right = NULL;
if(root == NULL){
root = newNode;
}
else if(root->data < value ){
root->right = insert(root->right , value);
}
else root->left = insert(root->left , value);
return root;
}
Comments
Post a Comment