#include<iostream>
using namespace std;
#include<vector>
#include<list>
#include<ctime>
#include<string>
#include<algorithm>
const int NUM = 10000;
int main()
{
srand(time(0));
vector<int> vi0(NUM);
for (int i = 0; i < NUM; i++)
vi0[i] = rand();
vector<int> vi(vi0);
list<int> li(vi0.begin(), vi0.end());
cout << "time of vector<int>: \n";
clock_t vector_start = clock();
sort(vi.begin(), vi.end());
clock_t vector_end = clock();
cout << "time is: " << (double)(vector_end - vector_start) / CLOCKS_PER_SEC << "s.\n";
cout << "time of list<int>: \n";
clock_t list_start = clock();
li.sort();
clock_t list_end = clock();
cout << "time is: " << (double)(list_end - list_start) / CLOCKS_PER_SEC << "s.\n";
cout << "time of swith list to vector: \n";
sort(vi0.begin(), vi0.end());
copy(vi0.begin(), vi0.end(), li.begin());
clock_t list_vector_start = clock();
copy(li.begin(), li.end(), vi.begin());
sort(vi.begin(), vi.end());
copy(vi.begin(), vi.end(), li.begin());
clock_t list_vector_end = clock();
cout << "time is : " << (double)(list_vector_end - list_vector_start) / CLOCKS_PER_SEC << "s.\n";
return 0;
}
十六章第九题
猜你喜欢
转载自blog.csdn.net/wode_0828/article/details/108846187
今日推荐
周排行