LEXICOGRAHIC SORTING
#include<stdio.h>
Void main()
{int l,I,j,k;
char
str[100]={‘\0’},ms[100][100]={‘\0’),temp[20];
J=0,k=0;
clrscr();
Printf(“\n enter the string”);
gets(str)
l=strlen(str);
for(i=0;i<=l;i++)
{if(str[i]!=’\0’;
J++;
K=0;
}
}
Ms[j][k]=’\0’;
For(i=0;i<=j;i++)
For(k=k+1;k<=j;k++)
{if(strcmp(ms[i],ms[k])>0)
{strcpy(temp,ms[i]);
Strcpy(ms[i],ms[k]);
Strcpy(ms[k],temp);
}
}
Printf(“\n the string after
sorting”);
For(i=0;i<=j;i++)
Printf(“%s\n”ms[i]);
getch();
}
OUTPUT
Enter a string
Orange apple grape banana
The string after sorting
apple
Banana
Grape
orange






0 comments:
Post a Comment