// Sort demo // JWME // 02 2020 #include "sort.h" #include "time.h" #include #include using std::cin; using std::cout; using std::endl; using std::sort; void generateVectorTest(); void timeSsort(); void timeAlgSort(); void timeMergeSort(); int main() { //timeSsort(); //timeAlgSort(); timeMergeSort(); cout << endl; return 0; } // Tests vector generation function void generateVectorTest() { vector v = randomVector(10); printVector(v); } // Times selection sort void timeSsort() { int n = 0; cout << "n: "; cin >> n; vector v = randomVector(n); clock_t t; t = clock(); ssort(v); t = clock() - t; cout << "sort took " << ((float)t) / CLOCKS_PER_SEC << " seconds" << endl; //printVector(v); } // Times STL sort void timeAlgSort() { int n = 0; cout << "n: "; cin >> n; vector v = randomVector(n); clock_t t; t = clock(); sort(v.begin(), v.end()); t = clock() - t; cout << "sort took " << ((float)t) / CLOCKS_PER_SEC << " seconds" << endl; } // Times JWME merge sort void timeMergeSort() { int n = 0; cout << "n: "; cin >> n; vector v = randomVector(n); clock_t t; t = clock(); mergesort(v); t = clock() - t; cout << "sort took " << ((float)t) / CLOCKS_PER_SEC << " seconds" << endl; //printVector(v); }