Pagini recente » Cod sursa (job #2850936) | Cod sursa (job #2558714) | Cod sursa (job #845263) | Cod sursa (job #3199249) | Cod sursa (job #559998)
Cod sursa(job #559998)
#include <stdio.h>
#define LIM 500005
FILE *f=fopen("algsort.in", "r"), *g=fopen("algsort.out", "w");
long v[LIM], sw, n, i;
void shell()
{
long inj;
inj=n;
while(inj>1)
{
inj/=2;
do
{
sw=0;
for (i=1;i<=n-inj;i++)
if (v[i]>v[i+inj])
{
sw=1;
v[i]=v[i]^v[i+inj];
v[i+inj]=v[i]^v[i+inj];
v[i]=v[i]^v[i+inj];
}
}while(sw);
}
}
void tipareste()
{
for (i=1;i<=n;i++)
fprintf(g, "%ld ", v[i]);
}
int main()
{
fscanf(f, "%ld", &n);
for (i=1;i<=n;i++)
fscanf(f, "%ld", &v[i]);
shell();
tipareste();
fclose(f);
fclose(g);
return 0;
}