Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void find_and_add(int value)
- {
- Node *temp = root;
- int rs = 0;
- bool ok = false;
- while (temp != NULL)
- {
- if (temp->data > value)
- {
- rs += temp->data;
- temp = temp->left;
- }
- if (temp->data < value)
- {
- rs += temp->data;
- temp = temp->right;
- }
- if (temp->data == value)
- {
- rs += temp->data;
- ok = true;
- break;
- }
- }
- if (ok)
- cout << rs;
- else
- cout << "lol";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement