// Oldham, Jeffrey D. // 2000Apr09 // CS1321 // Modified by: // Massingill, Berna L. // 2001Apr // Test Binary Search Trees // Use this file to test the binary search tree routines. #include #include // has EXIT_SUCCESS #include #include #include // has tolower() #include "bst.h" using namespace std; int main() { Tree t; const char prompt[] = "What next?\n" " q to quit\n" " i to insert\n" " r to remove\n" " ? to query\n" " p to print\n" "Your choice? "; string s; char c; cout << prompt; while (cin >> c) { switch(tolower(c)) { case 'q': return EXIT_SUCCESS; break; case 'i': cout << "Please enter the string to insert: "; if (cin >> s) t = insert(s, t); break; case '?': cout << "Please enter the string to query for: "; if (cin >> s) { if (query(s, t)) cout << "Found\n"; else cout << "Not found\n"; } break; case 'r': cout << "Please enter the string to remove: "; if (cin >> s) t = remove(s, t); break; case 'p': cout << "Contents of search tree:\n"; cout << t << endl; break; } cout << prompt; } return EXIT_SUCCESS; }