preorder
and postorder
traversals in BST.h from the book. To test your program,
use lab6main.cpp. The BST.h file from the book
already has two traversals: inorder and graph. The inorder traversal visits
the nodes in LVR (left-visit-right) order, which outputs the tree in sorted,
ascending order. The graph output gives a visual representation of the tree
structure with the root on the leftmost side of the screen and the rest of
the tree growing towards the right side of the screen.
For the preorder traversal, use inorder as a template but instead visit the nodes in VLR order. The output will not be sorted. For the postorder traversal, visit the nodes in LRV order. Note that inorder, preorder and postorder will all use two functions: a public interface and a private recurssive function. The public function just takes the output stream to use for printing. The private helper function takes an output streeam and the root of the subtree. Your public function should call the private function passing the root of the entire tree as the subtree to parse (see the inorder public function for an example).
Email your modified BST.h file to me.
BST<DataType>::BinNodePointer locptr = myRoot;but on Helios this will not compile. Instead, you need to use:
typename BST<DataType>::BinNodePointer locptr = myRoot;This new syntax is only required when you are trying to access a subclass of a template class. Likewise, if you are trying to use new to allocate a new tree node, the book has:
locptr = new BST<DataType>::BinNode(item);while you would need the following on newer C++ compilers:
locptr = new typename BST<DataType>::BinNode(item);