This looks like a homework assignment. Nobody but a college professor would use LISP.
We don't do your homework for you. But I can get you thinking.
LISP is a prefix language, so it is obvious that the binary tree structure you have is also prefix. A quick look confirms it.
So each node of the tree includes three list items, in this order:
- the node's element (a numeric atom)
- the left child branch of the tree (which is either a tree node or an empty list)
- the right child branch of the tree (which is either a tree node or an empty list)
Since it is a binary tree, all of the elements in the left child must be less than the element in the current node. Likewise, all of the elements in the right child must be greater than the element in the current node.
So your function should be able to tell which way to go by looking at the current node. 4 possibilites exist:
1. The current node is empty. You didn't find the search item.
2. The current node element equals the search value. You found it.
3. The current node element is larger than the search value. Recursively go left.
4. The current node element is smaller than the search value. Recursively go right.
MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
LISP is a prefix language, so it is obvious that the binary tree structure you have is also prefix.
What do you mean, in that it is "prefix"?
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177