Enter 5 numbers
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Sorted Array:
No. of instructions count:
Insertion_Sort(int a[],int n)
1 int i,j,key;
2. for(j=1;j <=n;j++)
3. key=a[j];
4. i=j-1;
5. while(i>=0 && a[i]>key)
6. a[i+1]=a[i];
7. i=i-1;
8. a[i+1]=key;
#include <stdio.h>
int count=0;
void main()
{
void getdata(int[10],int);
void putdata(int[10],int);
void insertion_sort(int a[],int);
int i,a[100],n;
clrscr();
printf("enter the value of n\n");
scanf("%d",&n);
getdata(a,n);
printf("\nbefore soring\n");
putdata(a,n);
insertion_sort(a,n);
printf("\nafter sorting\n");
putdata(a,n);
printf("\n for n = %d value of count is %d",n,count);
getch();
}
void getdata(int a[10],int n)
{
int k;
printf("enter the value for sorting\n");
for(k=1;k <= n;k++)
{
scanf("%d",&a[k]);
}
}
void putdata(int a[10], int n)
{
int k;
for(k=1;k <= n;k++)
{
printf("%d\t",a[k]);
}
printf("\n");
}
void insertion_sort(int a[],int n)
{
int key,j,i,temp;
count++;
for( j=2;j <= n;j++)
{
count++;
key=a[j];
count++;
i=j-1;
count++;
while(i>0 && a[i]>key)
{
count++;
count++;
a[i+1]=a[i];
count++;
i=i-1;
count++;
}
a[i+1]=key;
count++;
count++;
}
}
Best case | |
Average case | |
Worst case |