Please can you tell me how I can mergesort two arrays alphabetically and then print them?
If that is slightly difficult it will be fine if you can just tell me how to sort alphabetically forget the array part .
I need this for the language C only .
Thanks
Regards.
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
clrscr();
char st1[100],st2[100],tmp;
int i,j,len;
printf("Enter 2 strings:\n");
gets(st1);
gets(st2);
strcat(st1,st2);
len=strlen(st1);
printf("\n\n\n");
for(i=0;i<len;i++)
for(j=0;j<=i;j++)
if(st1<st1[j])
{
tmp=st1;
st1=st1[j];
st1[j]=tmp;
}
puts(st1);
getch();
}
Thanks
vysakh
Thanks for your help but thats of not much use to me because i need to sort words according to their alphabetical order and not the alphabets of the word or the sentences that are entered.
Your code is not serving my purpose.
However thanks a lot for the prompt help. Its appreciated.
Thanks .
Please help me anybody.....
do u specifically want merge sort?? then i need to refer. i will post it later if u want. here is the bubble sort function.
void bubble_sort(char *a[],int n)
{
int i,j;
char temp[20];
for(i=0;i<n;i++)
{
for(j=1;j<(n-i);j++)
{
if(strcmp(a[j-1],a[j])>0)
{
strcpy(temp,a);
strcpy(a,b);
strcpy(b,temp);
}
}
}
}
//use strcmpi() if u want a case insensitive search
//n is the number elements in the array
//strcpy is used to copy the string
Yes
Yes I need merge sort specifically merge sort .
Please try.
Thanks sorry for the trouble.
Regards