Cod sursa(job #314953)

Utilizator Magnuscont cu nume gresit sau fals Magnus Data 13 mai 2009 20:39:56
Problema Sortare prin comparare Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include <stdio.h>

int main()
{
 long v[5000],i,j,x,n;
 freopen("algsort.in","r",stdin);
 freopen("algsort.out","w",stdout);
 scanf("%ld",&n);
 for (i=1;i<n+1;i++)
 scanf("%ld",&v[i]);
 for (i=2;i<n+1;i++)
 {
  j=i;
  do
  {
   --j;
   if (v[j]>v[j+1]) {x=v[j];v[j]=v[j+1];v[j+1]=x;};
  }
  while ((j>1)&&(v[j-1]>v[j]));
 };
 for (i=1;i<n+1;i++) printf("%ld%c",v[i],' ');
 return 0;
}