Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
810 B
2
Indexable
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0, temp; i < n / 2; i += 1) {
        for (int j = 0; j < n / 2 - 1; j += 1) {
            if (a[j] > a[j + 1]) {
                temp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = temp;
            }
        }
    }

    for (int i = n / 2 + 1, temp; i < n + 1; i += 1) {
        for (int j = n / 2 + 1; j < n + 1; j += 1) {
            if (a[j] > a[j + 1]) {
                temp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = temp;
            }
        }
    }

    for (int i = 0; i < n; i++)
        cout << a[i] << " ";
    return 0;
}