Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. int n, num;
  6.  
  7. void swap(int *z, int *s)
  8. {
  9. if (*z>*s) {int x = *z; *z = *s; *s = x; }
  10. }
  11.  
  12. int main()
  13. {
  14. cout << "Введите количество элементов массива" << endl;
  15. cin >> n;
  16. cout << "Введите элементы массива" << endl;
  17. vector <int> a(n);
  18. for (int i = 0; i < n; i++) cin >> a[i];
  19. cout << "Сортировать по возрастанию или убыванию? (введите 1 или 2)" << endl;
  20. cin >> num;
  21. for (int i = 0; i < n-1; i++)
  22. for (int j = i+1; j < n; j++) swap(&a[i], &a[j]);
  23. if (num == 2) reverse(a.begin(), a.end());
  24. for (int i = 0; i < n; i++) cout << a[i] << " ";
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement