// Computer Science 367, Section 3, Fall 1997 // Instructor: Michael Siff (siff@cs.wisc.edu) // // Programming Assignment Three // // // FILE: main.C // // // This program is deigned to compare the heights of binary search trees, // red-black trees, and AVL trees. // -------- // Includes // -------- #include #include // sys/types.h and unistd are included for the Unix system call getpid() // which returns the process ID of the calling process (namely this // program). It provides a good "seed" to the random number generator for // since it should provide a different value each time the program is run. #include #include #include // pair template from C++ standard template library #include "bst.h" // binary search tree class template #include "red-black.h" // red-black tree class template // #include "avl.h" // AVL tree class template #include "bst-test.C" // various ways to test inserting into bsts // uncomment the following line if you wish to use displayBST // #include "bst-display.C" // displaying bsts int main() { size_t limit; BST bst0, bst1, bst2; RBT rbt0, rbt1, rbt2; // AVL avl0, avl1, avl2; srand(getpid()); // initialize random generator cout << "Enter the limit value (the number of integers " << "to be used in each test " << endl << "as well as the upper limit of those numbers)" << endl; cin >> limit; assert(limit > 0); int *A = new int[limit]; cout << endl << endl << "---------------------" << endl << "increasing order test" << endl << "---------------------" << endl << endl; for(size_t i=0; i < limit; i++) A[i] = i; cout << "BST: " << endl; insertFromArray(bst0, A, limit); cout << endl << "RBT: " << endl; insertFromArray(rbt0, A, limit); // cout << endl << "AVL: " << endl; // insertFromArray(avl0, A, limit); cout << endl << endl << "---------------------" << endl << "decreasing order test" << endl << "---------------------" << endl << endl; for(size_t i=limit; i > 0; i--) A[limit-i] = i; cout << "BST: " << endl; insertFromArray(bst1, A, limit); cout << endl << "RBT: " << endl; insertFromArray(rbt1, A, limit); // cout << endl << "AVL: " << endl; // insertFromArray(avl1, A, limit); cout << endl << endl << "-----------------" << endl << "random order test" << endl << "-----------------" << endl << endl; for(size_t i=0; i < limit; i++) A[i] = rand() % limit; cout << "BST: " << endl; insertFromArray(bst2, A, limit); cout << endl << "RBT: " << endl; insertFromArray(rbt2, A, limit); // cout << endl << "AVL: " << endl; // insertFromArray(avl2, A, limit); return EXIT_SUCCESS; }