Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main()
- {
- vector <int> arr;
- int size;
- int a;
- int temp;
- cout << "Введите кол-во элементов\n -> ";
- cin >> size;
- if (size <= 0) {
- cerr << "Invalid size" << endl;
- return 1;
- }
- cout << " Введите элементы для сортировки\n -> ";
- for (int i = 0; i < size; i++) {
- cin >> a;
- arr.push_back(a);
- }
- for (int i = size - 1; i >= 1; i--) {
- for (int j = 0; j < i; j++) {
- if (arr[j] > arr[j + 1]) {
- temp = arr[j];
- arr[j] = arr[j + 1];
- arr[j + 1] = temp;
- }
- }
- }
- for (int i = 0; i < size; i++) {
- cout << arr[i] << " ";
- }
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment