CIT 594 Tree Traversals and Searches
I've written some (pretty simple) methods to demonstrate tree traversals and searches.
There are three classes:
String valueand a
Vector children, which are available to the other classes; a constructor that takes a value as an argument; and methods to create and
adda single node (given its value), and to
Vector), with a default constructor and methods
static 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.