1: /** @file test_bst2.cpp 2: Test driver for the BinarySearchTree template class. 3: Contains, in addition to the default constructor, insert and display 4: member functions and their respective "helper functions". 5: @version 2.0 6: */ 8: #include <iostream> 9: using namespace std; 11: //Global variable used as a switch for tracing purposes. 12: bool tracingOn = false; 14: #include "utilities.h" 15: using Scobey::Pause; 16: using Scobey::userSaysYes; 18: //Keyword "export" not yet supported. 19: //Therefore separate compilation not possible. 20: #include "bst2.h" 21: #include "bst2.cpp" 23: int main() 24: { 25: Pause(0, "\nThis is a very short demonstration program for " 26: "binary search trees."); 27: tracingOn = userSaysYes("Want to see construction details?"); 29: vector<char> v_c; 30: cout << "\nEnter characters to put into a BST:\n"; 31: char ch; 32: while (cin.peek() != '\n') 33: { 34: cin >> ch; 35: v_c.push_back(ch); 36: } 37: cin.ignore(80, '\n'); 39: BinarySearchTree<char> bst_c; 40: for (vector<char>::size_type i=0; i<v_c.size(); i++) 41: { 42: if (tracingOn) cout << "Searching for a place to put " 43: << v_c.at(i) << " ...\n"; 44: bst_c.insert(v_c.at(i)); 45: } 46: cout << "\nHere are the tree contents in ascending order:\n"; 47: bst_c.display(cout); 48: Pause(0, "\n"); 51: vector<int> v_i; 52: cout << "\nEnter integers to place in a BST:\n"; 53: int k; 54: while (cin.peek() != '\n') 55: { 56: cin >> k; 57: v_i.push_back(k); 58: } 59: cin.ignore(80, '\n'); 61: BinarySearchTree<int> bst_i; 62: for (vector<int>::size_type j=0; j<v_i.size(); j++) 63: { 64: if (tracingOn) cout << "Searching for a place to put " 65: << v_i.at(j) << " ...\n"; 66: bst_i.insert(v_i.at(j)); 67: } 68: cout << "\nHere are the tree contents in ascending order:\n"; 69: bst_i.display(cout); 70: Pause(0, "\n"); 71: }