/*
 * This file name: BinarySearchTree.cpp
 *
 * This file contains the implementation of the Binary Search Tree
 * container class.
 */

#include "BinarySearchTree.h"

namespace uprm_icom4035 {
  
  /*********** DO NOT MODIFY THE FOLLLOWING TWO FUNCTIONS *****************/
  
  /*
   * This functions is used to print the elements in the tree
   * so as to mimic the actual structure of the tree.
   * It relies of the auxiliary function print_tree_aux().
   */
  template <typename BSTData, typename DataKey>
  void BinarySearchTree<BSTData,DataKey>::print_tree(ostream& out) {
    print_tree_aux(out, root, 0);
  }
  
  /*
   * This function is used to print the elements in the tree
   * in the following form:
   *    1) Print the right subtree.
   *    2) Print the root of the tree.
   *    3) Print the left subtree.
   * The parameter node is a pointer to the root of the tree
   * to be printed. The parameter n_space is used to print
   * blank spaces before printing the data contained on the 
   * root node.
   */
  template <typename BSTData, typename DataKey>
  void BinarySearchTree<BSTData,DataKey>::print_tree_aux
  (ostream& out, BSTNode<BSTData> *node, int n_space) {
    if (node != NULL){
      // print right child first
      print_tree_aux(out, node->right_child, n_space + 2);
      
      // print some space and then data in the root node
      for (int i=0; i < n_space; ++i){
	cout << " ";
      }
      cout << node->data << endl;
      
      // print left child
      print_tree_aux(out, node->left_child, n_space + 2);
    }
  }

  //////////////////////////////////////////////////////////////////////////

  /************* START ADDING FOR CODE FROM HERE **************************/
  
}
