Cod sursa(job #2122731)
Utilizator | Data | 5 februarie 2018 14:01:00 | |
---|---|---|---|
Problema | Sortare prin comparare | Scor | 40 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include<fstream>
using namespace std;
int main() {
ifstream in("algsort.in");
ofstream out("algsort.out");
int n;
in >> n;
int *x = new int[n];
for (int i = 0;i < n;++i) {
in >> x[i];
int j = i;
while (j > 0 && x[j] < x[j - 1]) {
int aux = x[j];
x[j] = x[j - 1];
x[j - 1] = aux;
j--;
}
}
for (int i = 0;i < n;++i)
out << x[i] << " ";
}