Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. void find_and_add(int value)
  2. {
  3. Node *temp = root;
  4. int rs = 0;
  5. bool ok = false;
  6. while (temp != NULL)
  7. {
  8. if (temp->data > value)
  9. {
  10. rs += temp->data;
  11. temp = temp->left;
  12.  
  13. }
  14. if (temp->data < value)
  15. {
  16. rs += temp->data;
  17. temp = temp->right;
  18. }
  19.  
  20. if (temp->data == value)
  21. {
  22. rs += temp->data;
  23. ok = true;
  24. break;
  25. }
  26.  
  27. }
  28. if (ok)
  29. cout << rs;
  30. else
  31. cout << "lol";
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement