Pagini recente » oni_2018_1_10 | Monitorul de evaluare | Istoria paginii utilizator/lulu | Cod sursa (job #384764) | Cod sursa (job #2912246)
#include <fstream>
#include <iostream>
#include <algorithm>
#include <climits>
#include <algorithm>
#include <cstring>
#include <iomanip>
#define DIM 100000
using namespace std;
//ifstream f("in.in");
//ofstream g("out.out");
ifstream f("algsort.in");
ofstream g("algsort.out");
int n,v[500005];
int main(){
f>>n;
for(int i=1;i<=n;i++){
f>>v[i];
}
for(int i=2;i<=n;i++){
int j=i;
while(j>1 && v[j/2]<v[j]){
swap(v[j],v[j/2]);
j/=2;
}
}
for(int i=n;i>=2;i--){
swap(v[i],v[1]);
int p=1;
int c=2;
while(c<=i-1){
if(v[c]<v[c+1] && c+1 <= i-1){
c++;
}
if(v[c]>v[p]){
swap(v[c],v[p]);
}else{
break;
}
p=c;
c=2*p;
}
}
for(int i=1;i<=n;i++){
g<<v[i]<<" ";
}
f.close();
g.close();
return 0;
}