Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <algorithm>
- #include <iostream>
- #include <iterator>
- #include <list>
- #include <random>
- #include <ctime>
- using namespace std;
- void main()
- {
- setlocale(0, "");
- list<int> numbers;
- mt19937 Settings(time(0));
- int a[301];
- int n;
- uniform_int_distribution<int> random(1, 10);
- do{
- cout << "Введите размер листа (300 max): ";
- cin >> n;
- }
- while (n > 300 || n < 0);
- try{
- for (int i = 0; i < n; i++)
- {
- a[i] = random(Settings);
- cout << a[i] << " ";
- }
- for (int i = 0; i < n; i++)
- {
- numbers.push_back(a[i]);
- }
- cout << endl;
- list<int>::iterator maxEl = max_element(numbers.begin(), numbers.end());
- list<int>::iterator minEl = min_element(numbers.begin(), numbers.end());
- cout << "Числа от Max до Min в нормальном порядке: ";
- for (list<int>::iterator i = maxEl; i != minEl; i--)
- cout << *i << " ";
- cout << *minEl << endl;
- cout << "Числа от Max до Min в обратном порядке: ";
- for (list<int>::iterator j = minEl; j != maxEl; j++)
- cout << *j << " ";
- cout << *maxEl << endl;
- }
- catch (exception ex){ throw exception(ex); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement