/* ****************************************************************************** * file name : vec_sort.cpp * author : Hung Q. Ngo * description: how to sort vectors, this is a quick hack just to show you how * you might do it; in your project 1, it might be best to design * a class Table, make "col_index" a member of that class, ****************************************************************************** */ #include #include #include // for setw() #include // for rand() and srand() #include // for time() #include "cb_sort.h" using namespace std; struct Record { size_t col_index; // the column used for indexing the record vector row; friend ostream& operator<<(ostream&, const Record&); }; /** * ----------------------------------------------------------------------------- * generate a random table with m rows and n columns, indexed by i <= n * ----------------------------------------------------------------------------- */ vector get_table(size_t m, size_t n, size_t index) { vector ret(m); vector row(n); srand(static_cast(time(0))); for (size_t i=0; i void print_vec(vector& vec) { for (int i=0; i vec = get_table(10, 3, 0); cout << "Before: \n"; print_vec(vec); randomized_quick_sort(vec, rec_cmp); cout << "After: \n"; print_vec(vec); return 0; }