// Computer Science 367, Section 3, Fall 1997 // Instructor: Michael Siff (siff@cs.wisc.edu) // // Programming Assignment Three // // // FILE: bst-test.C // // // These function templates are provided to test inserting into various // types of binary search trees. For all of these template functions, BSTType // should be a BST or a derived class of BST. #include template void insertFromArray(BSTType &bst, int A[], size_t n) // Inserts in order the integers in array A, where n is the number of // elements in the array. { for(size_t i=0; i < n; i++) bst.insert(i,A[i]); cout << "\tsize: " << bst.size() << endl; cout << "\theight: " << bst.height() << endl; } template void increasingOrderTest(BSTType &bst, size_t limit) // Inserts the integers from 0 up to but not including limit into the tree // and reports its resulting size and height. { for(size_t i=0; i < limit; i++) bst.insert(i,i); cout << "\tsize: " << bst.size() << endl; cout << "\theight: " << bst.height() << endl; } template void decreasingOrderTest(BSTType &bst, size_t limit) // Inserts the integers from limit down to, but not including 0 into the // tree and reports its resulting size and height. { for(size_t i=limit; i > 0; i--) bst.insert(i,i); cout << "\tsize: " << bst.size() << endl; cout << "\theight: " << bst.height() << endl; } template void randomOrderTest(BSTType &bst, size_t limit) // Inserts limit random integers in the range from 0 up to, but not // including limit into the tree and reports its resulting size and height. { for(size_t i=0; i < limit; i++) { size_t j = rand() % limit; bst.insert(j,j); } cout << "\tsize: " << bst.size() << endl; cout << "\theight: " << bst.height() << endl; }