Cod sursa(job #325043)
Utilizator | Data | 18 iunie 2009 16:36:36 | |
---|---|---|---|
Problema | Sortare prin comparare | Scor | 40 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include<fstream.h>
#define max 500000
ifstream f("algsort.in");
ofstream g("algsort.out");
int n,a[max];
void insertie()
{int x,k;
f>>n>>a[1];
for(int i=2;i<=n;i++)
{f>>x;k=i-1;
while(x<a[k])
{a[k+1]=a[k];
k--;
}
a[k+1]=x;
}
}
void afisare()
{
for(int i=1;i<=n;i++)
g<<a[i]<<' ';
}
int main()
{
insertie();
afisare();
return 0;
}