// Пример работы с STL библиотекой на основе вектора
#include <iostream>
#include <vector>
using namespace std;
int main () {
vector <int> a;
cout << "\n Модуль тест для работы с библиотекой STL";
cout << "Created vector a, size of vector: " << a.size() << "and capacity of vector: " << a.capacity();
cout << "Please resize vector:";
int N;
cin >> N;
a.resize(N);
cout << "\nOk";
cout << "Now vector a, size of vector: " << a.size() << "and capacity of vector: " << a.capacity();
....
}
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
int main () {
vector <int> a;
ostream_iterator <int> iter (cout, " ");
cout << "\n STL test";
cout << "\nCreated vector a, size of vector: " << a.size() << " and capacity of vector: " << a.capacity();
cout << "\nPlease resize vector:";
int N;
cin >> N;
a.resize(N);
cout << "\nOk";
cout << "Now vector a, size of vector: " << a.size() << "and capacity of vector: " << a.capacity();
for(int i = 0; i < N; ++i)
a[i] = rand() % 100;
clock_t start = clock();
cout << "\nbefore sort:" << endl;
copy (a.begin(), a.end(), iter);
sort (a.begin(), a.end(), greater<int>()); // Сортируем по убыванию
cout << "\nafter sort:" << endl;
copy (a.begin(), a.end(), iter);
clock_t end = clock();
cout << endl;
cout << "\n working time = " << (end - start) << " ticks";
return 0;
}
ostream_iterator <int> iter (cout, " "); ?
// понятно, что это начало замера времени, но что значит clock_t ?
clock_t start = clock();
copy (a.begin(), a.end(), iter);
for (int i=0; i<a.size(); i++) cout << a[i] << " ";
sort (a.begin(), a.end(), greater<int>());