| 
                                                
                                                    Insertion Sort
                                                
                                                
 
 
				/********************************************//*PROGRAM TO PERFORM INSERTION SORT*/
 /********************************************/
 #include<stdio.h>#include<conio.h>
 #define INF -999 void main(){
 int a[10],n,i,j,temp;
        clrscr();        a[0]=INF;printf("Enter the size of array: ");
 scanf("%d",&n);
 printf("\nEnter the elements of array:\n");
 for(i=1;i<=n;i++)
 {
 scanf("%d",&a[i]);
 }
 for(i=2;i<=n;i++)
 {
 temp=a[i];
 j=i-1;
 while(temp<a[j])
 {
 a[j+1]=a[j];
 j--;
 }
 a[j+1]=temp;
 }
        printf("\nAfter sorting the elements of array are:\n");for(i=1;i<=n;i++)
 {
 printf("%d ",a[i]);
 }
 getch();
 }
 
 http://
 http://
 
 Contributed by:
 Rohit kakria
 I am software developer, moderator of xpode.com
 
 Resourse address on xpode.com
 http://www.xpode.com/Print.aspx?Articleid=36
 Click here to  go on website  |