tree is a command-driven program, just like your
shell. Type help to see a list of tree commands.
1> help
Commands:
+ : find a node, inserting if it's not found.
- : remove a node (if it's in the tree).
.
.
2>
tree is for playing around with binary search trees; finding
and removing nodes are the most useful commands. Insert and remove
few nodes:
2> +10 +6 +14 +7 +5 -6 -2 +3
3>
(it doesn't matter whether you type a bunch of commands at once, or
only one at a time). Note that the visualizer animates the
insertions. The pause for each step can be controlled with the
delay command; for example
3> delay 250
4>
to make things move a bit faster. The code for finding and inserting
nodes is included with the project in treesearch.C. The header
file for the TreeNode class, tree.h, can be found in the course
include directory. It might be useful to compare the code with
the execution of the algorithm, to get a feel for how to make things
work.