Monday, January 24, 2011

Code : Insertsort example ( EX - 1)

//code (sap xep kieu) order insertsort

  • for you to learn about the algorithms sort and search.
  • This is an arrangement of the classic shape ever. 
  • Note see the post old, pre-sort algorithm and compared with each other.



 #include<stdio.h>
#include<conio.h>
#define n 10
void insertsort(int a[],int m)
{
 int i,k,y;
   for(k=1;k<n;k++)
   {
    y=a[k];
      for(i=k-1;i>=0 && y<a[i];i--)
       a[i+1]=a[i];
         a[i+1]=y;
   }
}
void main()
{
 int a[n],i;
   for(i=0;i<n;i++)
   {
    printf("\n a[%d]=",i);
      scanf("%d",&a[i]);
   }
   insertsort(a,n);
   printf("\n day sau khi sap xep la:\n");
   for(i=0;i<n;i++) printf("%d\t",a[i]);
   getch();
}

No comments:

Post a Comment

Popular Posts