#include<stdio.h>
#include<conio.h>
void main()
{
void insertion1(int [],int );
int n,a[20],j,i,index;
clrscr();
printf("Enter number of elements in array: ");
scanf("%d", &n);
for(i=0;i<n;i++)
{
printf("\nEnter the element: ");
scanf("%d", &a[i]);
}
insertion1(a,n);
printf("\nSorted element are: ");
for(i=0;i<n;i++)
{
printf("\t%d",a[i]);
}
getch();
}
void insertion1(int a[20],int n)
{
int i,j,index;
for(i=0;i<n;i++)
{
index=a[i];
j=i;
}
while((j>0)&&(a[j-1]>index))
{
a[j]=a[j-1];
j=j-1;
}
a[j]=index;
}
#include<conio.h>
void main()
{
void insertion1(int [],int );
int n,a[20],j,i,index;
clrscr();
printf("Enter number of elements in array: ");
scanf("%d", &n);
for(i=0;i<n;i++)
{
printf("\nEnter the element: ");
scanf("%d", &a[i]);
}
insertion1(a,n);
printf("\nSorted element are: ");
for(i=0;i<n;i++)
{
printf("\t%d",a[i]);
}
getch();
}
void insertion1(int a[20],int n)
{
int i,j,index;
for(i=0;i<n;i++)
{
index=a[i];
j=i;
}
while((j>0)&&(a[j-1]>index))
{
a[j]=a[j-1];
j=j-1;
}
a[j]=index;
}
0 Comments