Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Binary Tree Insertion #2

Open
ymohit1603 opened this issue Jul 8, 2023 · 0 comments
Open

Update Binary Tree Insertion #2

ymohit1603 opened this issue Jul 8, 2023 · 0 comments

Comments

@ymohit1603
Copy link

Hey, there is a problem in the code of Binary tree insertion . I think there is a missing return statement in the if(root==NULL) part.
Correct would be
node * insert(node * root, int value)
{
node * newNode = new node();
newNode->data = value;
newNode->left = NULL;
newNode->right = NULL;
if(root == NULL){
root = newNode;
return root; //correction part

}
else if(root->data < value ){
    root->right = insert(root->right , value);
} 
else root->left = insert(root->left , value);
return root;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant