Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int bst::insert()
- {
- int add = 1;
- /* cout << "Enter value you wish to insert \n";
- cin >> add;
- cin.ignore(100, '\n');*/
- node * temp = new node;
- temp->data = add;
- insert(&root, add, &temp);
- return 1;
- }
- int bst::insert(node ** root, int add, node ** temp)
- {
- if(root == NULL);
- {
- return 0;
- }
- if(add >= (*root)->data)
- {
- //go right
- if((*root)->right != NULL)
- {
- insert(&(*root)->right, add, temp); //check if correct
- }
- else
- {
- (*root)->right = *temp; // check if correct
- (*temp)->left = NULL;
- (*temp)->right = NULL;
- }
- }
- else if(add < (*root)->data)
- {
- if((*root)->left != NULL)
- {
- insert(&(*root)->left, add, temp); //check if correct
- }
- else
- {
- (*root)->left = *temp; // check if correct
- (*temp)->left = NULL;
- (*temp)->right = NULL;
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement