|
|
|
|
Input a number to put in the tree: 5 Done adding numbers? (y/n): n Input a number to put in the tree: 3 Done adding numbers? (y/n): n Input a number to put in the tree: 4 Done adding numbers? (y/n): y Tree currently has the following values: Here 0 Here Here 5 Here 3 Here Here 4 Here Here Here Here are sorted values: 4 3 5 Input a number to search for in the tree: 5 5 is in the tree! Done searching numbers? (y/n): n Input a number to search for in the tree: 4 Sorry, 4 was not in the tree Done searching numbers? (y/n): n Input a number to search for in the tree: 3 Sorry, 3 was not in the tree Done searching numbers? (y/n): y Goodbye! Process returned 0 (0x0) execution time : 31.518 s Press ENTER to continue. |
|
|
|
|
|
|
if ((subtree->getLeft() == nullptr && subtree->getRight()) == nullptr)
if the current node's left and right subtree's are empty (both m_left and m_right are looking at nullptr) then return the nullptr to indicate we didn't find the value |
|
|
|
|
This way m_root's value won't change during runtime? |
|
|
|
|
Input a number to put in the tree: 5 Done adding numbers? (y/n): n Input a number to put in the tree: 4 Done adding numbers? (y/n): n Input a number to put in the tree: 3 Done adding numbers? (y/n): n Input a number to put in the tree: 2 Done adding numbers? (y/n): n Input a number to put in the tree: 10 Done adding numbers? (y/n): y Tree currently has the following values: 5 4 3 2 10 Here are sorted values: 2 3 4 10 Input a number to search for in the tree: |