Pagini recente » Cod sursa (job #878699) | Cod sursa (job #169613) | Cod sursa (job #3003645)
#include <bits/stdc++.h>
using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");
const int NMAX = 5e5 + 5;
int a[NMAX], n;
int main(){
f >> n;
for(int i=1;i<=n;++i){
f >> a[i];
}
for(int k = 0; k < n; ++k){
bool ok = false;
for(int i = 2; i <= n - k; ++i){
if(a[i] < a[i-1]){
swap(a[i], a[i-1]);
ok = true;
}
}
if(!ok){
break;
}
else{
ok = false;
}
}
for(int i=1;i<=n;++i){
g << a[i] << " ";
}
return 0;
}