Insertion sort example in C

 /*  */
 # define n 6
 int x[]={4, 3, 6, 2, 8, 9};
 main( )
 {
       int I, t, j,.
       printf(“\n\n Input data: \n \n”);
       for(I=0; I<n; I++)
       printf(*%3d*, x[I]);
       printf(*\n*);
       for I=1; I<n; I++)
       for(j=1, j>0 && x[j]<x[j-1]; j — —)
       {
           t=x[j];
           x[j]=x[j-1];
           x[j-1]=t;
       }
       printf(“\n\n Output data: \n \n”);
       for(I=0; I<6; I++)
       printf(“%3d”, x[I]);
       printf(“n”);
 }

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.