I need some help with the following problem. There is a Search Tree (Binary Search Tree) and I need to find a particular element, so to search the Search Tree. But this only needs to be displayed in Pseudocode (so the actual search tree isn't needed, so just for an example the root is 75 and the element that needs to be searched is 24).
So for example step 1: Print Root, 2: Print Tree....(until the correct element has been found).
I have done this so far:
1) def findval (node, lookForElement):
2) while node is not null:
3) if node.val is equal to lookForElement:
4) break
5) if node.val is less than lookForElement:
6) node = node.right
7) else:
8) node = node.left
9) return node
10) if node is null:
11) print "tree is empty"
But I think this would only work if the the searched element is the next element down, but the searched element could be a few branches down so therefore how would I correctly loop?