#include <iostream>
#include <list>
#include <vector>
#include <algorithm>
#include <ctime>
using namespace std;
int main() {
vector<int> vi0;
clock_t start;
clock_t end;
int size = pow(10, 6);
cout << "Creating a vector with " << size << " random values" << endl;
for (int i = 0; i < size; i++) {
vi0.push_back(rand());
}
vector<int> vi(vi0);
list<int> li = list<int>(vi0.begin(), vi0.end());
cout << "Starting vector sort" << endl;
start = clock();
sort(vi.begin(), vi.end());
end = clock();
double vecSort = (double)(end - start) / CLOCKS_PER_SEC;
cout << "Starting list sort" << endl;
start = clock();
li.sort();
end = clock();
double liSort = (double)(end - start) / CLOCKS_PER_SEC;
li = list<int>(vi0.begin(), vi0.end());
cout << "Starting list-vector-list sort" << endl;
start = clock();
copy(li.begin(), li.end(), vi.begin());
sort(vi.begin(), vi.end());
copy(vi.begin(), vi.end(), li.begin());
end = clock();
double liVecSort = (double)(end - start) / CLOCKS_PER_SEC;
cout << "Vector sort: " << vecSort << " seconds.\n" <<
"List sort: " << liSort << " seconds.\n" <<
"List -> Vector sort -> List: " << liVecSort << " seconds." << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bGlzdD4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGN0aW1lPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewoJdmVjdG9yPGludD4gdmkwOwoJCWNsb2NrX3Qgc3RhcnQ7CgkJY2xvY2tfdCBlbmQ7CgkJaW50IHNpemUgPSBwb3coMTAsIDYpOwoJCWNvdXQgPDwgIkNyZWF0aW5nIGEgdmVjdG9yIHdpdGggIiA8PCBzaXplIDw8ICIgcmFuZG9tIHZhbHVlcyIgPDwgZW5kbDsKCQlmb3IgKGludCBpID0gMDsgaSA8IHNpemU7IGkrKykgewoJCQl2aTAucHVzaF9iYWNrKHJhbmQoKSk7CgkJfQoJCXZlY3RvcjxpbnQ+IHZpKHZpMCk7Cgk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