// Using the standard library to code Merge Sort // Ignore the iterators for now.... #include #include #include #include #include using namespace std; void msort( vector::iterator begin, vector::iterator end) { if ((begin==end) or (begin == end-1)) return; vector::iterator mid = begin + (end - begin) / 2; msort(begin, mid); msort(mid, end); inplace_merge(begin, mid, end); } int main() { const int seed = static_cast(time(0)); srand(seed);//set random number differently each run const int Biggest = 100000; const int Size = 50000; const int Sample = 100; double total_time =0.0; for(int s = 0; s /*******/; for(int i = 0; i< Size; i++) { data.push_back(rand()%Biggest); } time_t time1 = time(0); msort(data.begin(), data.end()); time_t time2 = time(0); total_time+= difftime(time2, time1); } cout << "Selection Sort. Size =" << Size << ", mean time ="; cout << total_time /Sample; return 0; }