Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <list>
- using namespace std;
- void SortList(list<int>& lst){
- lst.sort();
- }
- void PrintList(list<int>& lst) {
- for (int n : lst) {
- cout << n << " ";
- }
- cout << endl;
- }
- int main()
- {
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- srand(time(0));
- list<int> numbers{};
- int N{}, i{}, temp_number{};
- while (true) {
- cout << "Введіть бажану кількість елементів у списку (від 2 до 10): ";
- cin >> N;
- if (cin.fail() || cin.peek() != '\n' || N < 2 || N > 10) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Число було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- cout << "Згенерований список: ";
- for (i = 0; i < N; i++) {
- temp_number = rand() % 201 - 100;
- numbers.push_back(temp_number);
- cout << temp_number << " ";
- }
- cout << endl;
- SortList(numbers);
- cout << "Відсортований список: ";
- PrintList(numbers);
- }
Advertisement
Advertisement