/* Sample Driver for BST EE 312 - Fall 2018 The BST should work for any data type. Types that are user-defined must have the << operator overloaded. */ #include "BST.h" #include #include #include using namespace std; template void print(vector vec) { for(int i = 0; i < vec.size(); i++) cout << vec[i]<< endl; } int main() { BST bst; bst.add(50); bst.add(25); bst.add(3); bst.add(55); bst.add(77); cout << "in order traversal of the int BST: " << endl; vector v = bst.inOrder(); print(v); cout << endl; ifstream inFile; inFile.open("test.txt"); BST stringBST; string s; inFile >> s; while(inFile) { cout << "inserting word from the input file: " << s << endl; stringBST.add(s); inFile >> s; } cout << endl; cout << "inorder traversal of stringBST is: " << endl; print(stringBST.inOrder()); string minValue = stringBST.getMin(); cout << "Min string in stringBST = " << minValue << endl; cout << "Number of nodes in stringBST: " << stringBST.size() << endl; cout << endl; cout << "Remove \"tree\" from stringBST and print inorder traversal: " << endl; s = "tree"; stringBST.remove(s); print(stringBST.inOrder()); cout << endl; cout << "Number of nodes in stringBST: " << stringBST.size() << endl; cout << endl; // Make a deep copy of stringBST and print it cout << "making deep copy of stringBST..." << endl; BST stringBST2 = stringBST; vector two = stringBST2.inOrder(); print(two); // Remove a value from stringBST and then print both string BSTs stringBST.remove("This"); cout << "inorder traversal of stringBST:" << endl; print(stringBST.inOrder()); cout << "inorder traversal of stringBST2:" << endl; print(stringBST2.inOrder()); }