2dix-The Student Choice
Log in Register now

C++ Program of INSERTION SORT

Write a Program of INSERTION SORT

#include<iostream.h> 
#include<conio.h>

void main()

{

int i,j,s,temp,a[20];

clrscr();

printf("\nEnter size of the array: ");

scanf("%d",&s);

printf("\nEnter %d elements in to the array:",s);

for(i=0;i<s;i++)

scanf("%d",&a[i]);

for(i=1;i<s;i++)

{

temp=a[i];

31

By:Ms-Kamalpreet Kaur (14960)

j=i-1;

while((temp<a[j])&&(j>=0))

{

a[j+1]=a[j];

j=j-1;

}

a[j+1]=temp;

}

printf("\nAfter sorting the elements are: ");

for(i=0;i<s;i++)

printf(" %d",a[i]);

getch();

}




Note:
      If you want to change in this program please write through the comment on this page. you can also past similar program 
                 of c++ with output.your comment is valuable to the other user and person.


comments (0)

avatar