#include #include #include #include #include "HeapSort.h" using namespace std; int main(int argc, char * argv[]) { int searchSize{10}; vector target; vector standard; bool error {false}; int errors{0}; srand(static_cast(time(nullptr))); if (argc > 1) { int tmp = stoi(argv[1]); if (tmp > 10) { searchSize = tmp; } } for(int i = 0; i < searchSize; i++) { int tmp = rand(); target.push_back(tmp); standard.push_back(tmp); } // see https://en.cppreference.com/w/cpp/chrono auto time1 = chrono::high_resolution_clock::now(); sort(begin(standard), end(standard)); auto time2 = chrono::high_resolution_clock::now(); HeapSort(target); auto time3 = chrono::high_resolution_clock::now(); chrono::duration dtime1 = time2 - time1, dtime2 = time3 - time2; cout << "Standard Library Time: " << dtime1.count() << " seconds." << endl; cout << "Heap Time: " << dtime2.count() << " seconds." << endl; cout << endl; // check and report any errors for(size_t i=0; i < standard.size(); i++) { if (standard[i] != target[i]) { cout << "Error at position " << i << endl; error = true; errors ++; } } if (error) { cout << "There were at total of " << errors << " misplaced elements" << endl; } for(int i =0; i < static_cast(target.size())-1; i++) { if (target[i] > target[i+1]) { cout << "Sort Error" << endl; return 1; } } return 0; }