You are viewing a single comment's thread. Return to all comments →
It is possible in 16 lines without recursion also. Just look at it once.
node * insert(node * root, int value) { node* newnode = new node; newnode->data = value; newnode->left = NULL; newnode->right = NULL; if(root == NULL) root = newnode; node *temp = root; while(temp->left && value < temp->data){ temp = temp->left;} while(temp->right && value > temp->data){ temp = temp->right;} while(temp->left && value < temp->data){ temp = temp->left;} if(value > temp->data) temp->right = newnode; if(value < temp->data) temp->left = newnode; return root; }
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Search Tree : Insertion
You are viewing a single comment's thread. Return to all comments →
It is possible in 16 lines without recursion also. Just look at it once.