#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void insert(char a[][25],int n)
{
int i,j,k;
char key[25];
for(i=1;i<n;i++)
{
strcpy(key,a[i]);
for(j=i-1;j>=0;j--)
{
if(strcmp(key,a[j])>=0)break;
strcpy(a[j+1],a[j]);
}
strcpy(a[j+1],key);
printf("After pass %d:\n",i);
for(k=0;k<n;k++)
printf("%s\n",a[k]);
}
}
int main()
{
int n,i;
char a[25][25];
printf("Enter the number of elements to sort\n");
scanf("%d",&n);
printf("Enter the strings to be sorted\n");
for(i=0;i<n;i++)
scanf("%s",a[i]);
insert(a,n);
printf("After sorting\n");
for(i=0;i<n;i++)
printf("%s\n",a[i]);
}
Thanks to the senior who gave us the permission to copy their code :P
No comments:
Post a Comment