Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int n, num;
- void swap(int *z, int *s)
- {
- if (*z>*s) {int x = *z; *z = *s; *s = x; }
- }
- int main()
- {
- cout << "Введите количество элементов массива" << endl;
- cin >> n;
- cout << "Введите элементы массива" << endl;
- vector <int> a(n);
- for (int i = 0; i < n; i++) cin >> a[i];
- cout << "Сортировать по возрастанию или убыванию? (введите 1 или 2)" << endl;
- cin >> num;
- for (int i = 0; i < n-1; i++)
- for (int j = i+1; j < n; j++) swap(&a[i], &a[j]);
- if (num == 2) reverse(a.begin(), a.end());
- for (int i = 0; i < n; i++) cout << a[i] << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement