Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<list>
- #include <algorithm>
- #include <iterator>
- #include <ctime>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "RUS");
- srand(time(NULL));
- /*_______________________________________________________________________________________*/
- //1 номер
- /*_______________________________________________________________________________________*/
- cout << "Number 1.\n\n";
- vector<int>myVector(10); //создаём вектор и задаём ему длину
- cout << "Initial vector: ";
- for (int i = 0; i < 10; i++) { //генерируем числа, не привышающие 1000
- myVector[i] = rand() % 10;
- cout << myVector[i] << " ";
- }
- sort(myVector.begin(), myVector.end()); // сортировка
- cout << endl << "Changed vector: ";
- for (int i = 0; i < 10; i++) {
- cout << myVector[i] << " ";
- }
- cout << endl << endl << "_____________________________";
- /*_______________________________________________________________________________________*/
- //2 номер
- /*_______________________________________________________________________________________*/
- cout << "\nNumber 2.\n\n";
- cout << "Initial vector: ";
- list<int>myList;
- int n = 10;
- for (int i = 0; i < n; i++) { //генерируем числа в список
- myList.push_back(rand() % 10);
- }
- for (auto i = myList.begin(); i != myList.end(); i++) { //выводим
- cout << *i << " ";
- }
- auto iter_to_max = max_element(myList.end(), myList.begin());
- int index_max = distance(myList.begin(), iter_to_max);
- list<int>::iterator index_last;
- while (true) {
- index_max++;
- for (list<int>::iterator iter = myList.begin(); iter != myList.end(); iter++) //нахождение номера последнего элемента списка
- index_last = iter;
- myList.push_front(*index_last); //перетаскиваем последний элемент в начало последовательности
- myList.resize(10);
- if (index_max == myList.end()) { //если максимальный элемент равен конечному, то заканчиваем на этом
- for (list<int>::iterator iter = myList.begin(); iter != myList.end(); iter++)
- index_last = iter;
- myList.push_front(*index_last);
- myList.resize(10);
- break;
- }
- }
- cout << endl << "Changed vector: ";
- for (auto i = myList.begin(); i != myList.end(); i++) { //вывод изменненого
- cout << *i << " ";
- }
- cout << endl << endl << "_____________________________";
- //resize
- /*_______________________________________________________________________________________*/
- //3 номер
- /*_______________________________________________________________________________________*/
- cout << "\nNumber 3.\n\n";
- vector<int>myVector3(10); //создаём вектор и задаём ему длину
- cout << "Initial vector: ";
- for (int i = 0; i < 10; i++) { //генерируем числа, не привышающие 1000
- myVector3[i] = rand() % 10;
- cout << myVector3[i] << " ";
- }
- cout << endl << "Changed vector: ";
- make_heap(myVector3.begin(), myVector3.end());
- for (vector<int>::iterator it = myVector3.begin(); it != myVector3.end(); it++) { //выводим результат
- cout << *it << " ";
- }
- cout << endl << endl << "_____________________________";
- /*_______________________________________________________________________________________*/
- //4 номер
- /*_______________________________________________________________________________________*/
- cout << endl << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment