Homework 4: Traveller of Trees

DRAFT: Open for comment in the discussion forum.

Educational Objectives: On successful completion of this assignment, the student should be able to

Operational Objectives: implement three binary tree iterator types: BinaryTreePostorderIterator<T>, BinaryTreePreorderIterator<T>, and BinaryTreeLevelorderIterator<T> as declared in the file tbt.h.

Deliverables: Two files:

tbt5.cpp // contains implementations of preorder, postorder, and levelorder iterators
log.txt  // development & testing log file

Background

Required background knowledge is reviewed in Trees 1 , Trees 2 , Trees 3

The binary tree class and its associated navigator class, iterator classes, and functions are all defined/prototyped in the header file tbt.h. Slave files are used to house implementations of various components of the TBinaryTree. The files in the package are as follows:

tbt.h        // class definitions and function/operator prototypes
tbt1.cpp     // implements core of TBinaryTree, TBinaryTreeNavigator, and non-member operators
tbt2.cpp     // implements function bool Load(TBinaryTree<T>&, const char*)
tbt3.cpp     // implements 1-argument TBinaryTree<T>::Dump(std::ostream&)
tbt4.cpp     // implements class InorderIterator
tbt5.cpp     // implements classes PreorderIterator, PostorderIterator, LevelorderIterator,
tbt6.cpp     // implements TBinaryTree<T> rotation methods

(Recall that a "slave" file is one that is included into its master file with a #include<> directive. Slave files should not define a namespace or #include their associated header file, otherwise an infinite loop of #includes is created. The effect on client programs is that only the master header file is #included into source files. A slave file makes no sense to the compiler by itself. A slave file only makes sense when considerd a logical part of its master file.)

Procedural Requirements:

  1. Complete the implementations of the three alternative iterator types (preorder, postorder, and levelorder) for binary trees, as defined in LIB/tcpp/tbt.h. Place these implementations in file tbt5.cpp. Be sure to log your activities in log.txt.
  2. Test your implementations thoroughly, logging the results in log.txt.
  3. Turn in the files tbt5.cpp and log.txt using the hw4submit.sh submit script.

    Warning: Submit scripts do not work on the program and linprog servers. Use shell.cs.fsu.edu to submit assignments. If you do not receive the second confirmation with the contents of your assignment, there has been a malfunction.

Technical Requirements and Specifications

  1. Implement the three iterator classes as specified in tbt.h, starting with LIB/hw4/tbt5.partial.
  2. Use iteration-based depth-first search to implement PostorderIterator.
  3. Use stack-based depth-first search to implement PreorderIterator.
  4. Use queue-based breadth-first search to implement LevelorderIterator.
  5. Note that PreorderIterator and LevelorderIterator are somewhat curtailed forward iterators, while PostorderIterator is a fully functional bidirectional iterator.

Hints