|
CIT 594 Tree Traversals and Searches |
I've written some (pretty simple) methods to demonstrate tree traversals and searches.
There are three classes:
TreeTree has
a String value and a Vector children, which are
available to the other classes; a constructor that takes a value as an argument;
and methods to create and add a single node (given its value),
and to add a subtree.QueueVector),
with a default constructor and methods add(Object), get(),
addAll(Collection), and isEmpty().TreeTraversalsstatic void preorderPrint(Tree node)static void preorderPrint(Tree node, String indent)static void postorderPrint(Tree node)static void postorderPrint(Tree node, String indent)static boolean dfs(Tree root)static boolean recursiveDfs(Tree node)static boolean bfs(Tree root)The only interesting class is available as TreeTraversals.java. (There are also minimal Tree.java and Queue.java classes.) The whole thing, as a BlueJ package, is available as a zip file.