Cod sursa(job #2983866)

Utilizator TheGodFather2131Alexandru Miclea TheGodFather2131 Data 23 februarie 2023 10:54:42
Problema Sortare prin comparare Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 kb
#include <iostream>
using namespace std;

int v[10005];
int n;

//bubble sort
int main(){
    
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> v[i];
    }

    int ok = 1;
    while(ok){
        ok = 0;
        for (int i = 1; i < n; i++){
            int j = i + 1;
            if (v[i] > v[j]){
                ok = 1;
                int aux = v[i];
                v[i] = v[j];
                v[j] = aux;
            }
        }
        // for (int i = 1; i <= n; i++) cout << v[i] << ' ';
        // cout << endl;
    }

    for (int i = 1; i <= n; i++) cout << v[i] << ' ';
    
    return 0;
}