CSC 311

Winter 2002

Assignment 5

Due: Monday, March 11th.

As we discussed in class, your assignment is to complete writing a function to balance a binary search tree.  This function requires 4 steps:

  1. Copy the tree to a queue; we did this with the function bst_copyToQueue.
  2. De-allocate the memory assigned to the tree using tree_clear from bintree.h.
  3. Copy the queue to an array; we did this with the function copyQueueToArray.
  4. Insert the data from the array into a new (and balanced) tree using a function called bst_copyFromArray.

Your job is to write the function for step 4.  It should be recursive and it should use the technique we discussed in class.

The program balancebst.cpp contains the code for steps 1, 2, and 3 along with a main function to test it all.  Modify that program by adding the function bst_copyFromArray.