Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 05-03-2005, 06:17 PM   #1 (permalink)
Alpha Geek
 
godsownman's Avatar
 
Join Date: Feb 2005
Location: Bombay
Posts: 879
Default C programming help


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.
godsownman is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 05-03-2005, 08:06 PM   #2 (permalink)
Alpha Geek
 
vysakh's Avatar
 
Join Date: Sep 2004
Location: Old trafford
Posts: 860
Default

#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[i]<st1[j])
{
tmp=st1[i];
st1[i]=st1[j];
st1[j]=tmp;
}
puts(st1);
getch();
}
__________________
Incompatible message format
vysakh is offline  
Old 06-03-2005, 06:58 PM   #3 (permalink)
Alpha Geek
 
godsownman's Avatar
 
Join Date: Feb 2005
Location: Bombay
Posts: 879
Default 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.....
godsownman is offline  
Old 07-03-2005, 01:40 AM   #4 (permalink)
In The Zone
 
hafees's Avatar
 
Join Date: Feb 2004
Location: Kerala
Posts: 405
Default

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
__________________
Quitters Never Win & Winners Never Quit!
hafees is offline  
Old 07-03-2005, 07:01 PM   #5 (permalink)
Alpha Geek
 
godsownman's Avatar
 
Join Date: Feb 2005
Location: Bombay
Posts: 879
Default Yes

Yes I need merge sort specifically merge sort .
Please try.



Thanks sorry for the trouble.

Regards
godsownman is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:42 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2