/* ****************************************************************************** * file name : driver.cpp * author : Hung Q. Ngo * description: test a few template sorting algorithms ****************************************************************************** */ #include #include #include // for rand() and srand() #include // for time() // #include "templ_sort.h" #include "cb_sort.h" using namespace std; /** * ----------------------------------------------------------------------------- * print a vector of Item_Type, finish with a new line * assumes compiler knows how to cout << Item_Type * ----------------------------------------------------------------------------- */ template void print_vec(vector& vec) { for (int i=0; ib ? -1 : (a vec; vec.push_back(1.5); vec.push_back(-2.5); vec.push_back(5.3); vec.push_back(-2); vec.push_back(4); cout << "Sorting doubles in increasing order" << endl; cout << "Before: "; print_vec(vec); randomized_quick_sort(vec); cout << "After: "; print_vec(vec); // sorting doubles in reversed order cout << "Sorting doubles in decreasing order" << endl; cout << "Before: "; print_vec(vec); insertion_sort(vec, reverse_cmp); cout << "After: "; print_vec(vec); // sorting strings alphabetically vector str_vec(6); str_vec[0] = "Alex"; str_vec[1] = "Carol"; str_vec[2] = "George"; str_vec[3] = "Charles"; str_vec[4] = "Alice"; str_vec[5] = "Knuth"; cout << "Sorting strings alphabetically" << endl; cout << "Before: "; print_vec(str_vec); insertion_sort(str_vec, str_cmp); cout << "After: "; print_vec(str_vec); }