// testsorts.cpp - tests implementations of the Sorter hierarchy // cmc, 11/2/2013 #include using namespace std; #include "mergesorter.h" #include "quicksorter.h" #include "pqsorter.h" #include "arraypq.h" #include "listpq.h" #include "heappq.h" int main() { double x[] = {406, 198, 961, 238, 910, 188, 467, 639, 125, 581, 144, 354, 812, 716, 150, 753, 387, 491, 788, 624, 263, 545, 908, 829, 287, 913, 811, 245, 997, 701, 806, 76, 368, 792, 645, 868, 87, 702, 403, 698, 772, 793, 678, 37, 328, 893, 80, 721, 213, 251, 375, 18, 541, 117, 315, 136, 743, 519, 863, 359, 340, 283, 908, 600, 620, 684, 479, 210, 685, 23, 466, 641, 985, 803, 139, 106, 463, 575, 461, 572 }; int nx = (sizeof x) / sizeof(double); int choice = 0; Sorter *sorter; cout << "Before sorting:" << endl; for (int i=0; i "; cin >> choice; switch (choice) { case 1: sorter = new MergeSorter(); break; case 2: sorter = new QuickSorter(); break; case 3: case 4: case 5: PQ *queue; if (choice == 3) queue = new ArrayPQ(); else if (choice == 4) queue = new ListPQ(); else queue = new HeapPQ(); sorter = new PQSorter(*queue); break; default: cerr << "bad choice: " << choice << endl; cerr << "exiting" << endl; return 1; } sorter->sort(x, nx); cout << "After sorting:" << endl; for (int i=0; i