(Last Revision: 10/31/2005)

Wprint PROCEDURE FOR PRINTING BINARY TREES.


Below is a recursive algorithm on which you can base your tree-printing function. You will want to add more parameters to indicate
  1. the lowest level of the tree to be printed -- for example, the parameter would be 2 if you want no more than 2 levels of the tree to be printed.
  2. whether the family tree rooted at the input node is to be printed, or whether the binary search tree rooted at the node is to be printed.
Below we assume that you have implemented a simple procedure (here generically called PrintNode) which prints out the appropriate contents of a node in the tree, "tabbed over" toward the right side of the output area by an amount proportionate to the parameter "currentLevel".

void Wprint (ptrType pointerToTreeNode, int currentLevel) ;
{
  if  (pointerToTreeNode != NULL)
     {
         Wprint (right-child pointer of "TreeNode", currentLevel+1) ;
	 PrintNode(pointerToTreeRoot, currentLevel) ;
         Wprint (left-child pointer of "TreeNode", currentLevel+1) ;
      }
}