User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,565 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,581 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 1558 | Replies: 5
Reply
Join Date: Oct 2007
Posts: 6
Reputation: woozy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
woozy woozy is offline Offline
Newbie Poster

Question Sort strings in lexicographical order but not to use built-in string functions

  #1  
Oct 21st, 2007
Hi,

I want to write a function to perform lexicographical sorting using a simple bubble sort technique. So far I've got the basic code running, but something is not right. I can tell the algorithm is wrong but cannot fix it, please help.

int bubble_sort(char **words, int num_word)
{
	int x, y, z;
	char *temp;

	for (x = 0; x < num_word; x++)
	{
		for (y = 0; y < (num_word-1); y++)
		{
			for (z = 0; z < (WORD_SIZE+1); z++)
			{
				if (words[y][z] < words[y+1][z])
				{
					temp = words[y+1];
					words[y+1] = words[y];
					words[y] = temp;
					break;
				}
				else
				{
					continue;
				}
			}
		}
	}

	return 0;
}

I've tried not to use the third inner loop, but then it will just perform the first letter comparison...And yes, let me stress that strcmp or strncmp should not be used...

Thank you in advance.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,832
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 324
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Sort strings in lexicographical order but not to use built-in string functions

  #2  
Oct 21st, 2007
... the hat of 'is this a cat in a hat?'
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: Sort strings in lexicographical order but not to use built-in string functions

  #3  
Oct 21st, 2007
Reply With Quote  
Join Date: Oct 2007
Posts: 6
Reputation: woozy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
woozy woozy is offline Offline
Newbie Poster

Re: Sort strings in lexicographical order but not to use built-in string functions

  #4  
Oct 21st, 2007
Lol, Salem, you caught me right over here, eh?
Reply With Quote  
Join Date: Aug 2005
Posts: 4,832
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 324
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Sort strings in lexicographical order but not to use built-in string functions

  #5  
Oct 21st, 2007
Yes but you are no different from the hundreds of other chumps who do exactly the same thing.

They sign up to as many forums as possible, then cherry pick the answers they see fit.

That type of behaviour is annoying at best.
... the hat of 'is this a cat in a hat?'
Reply With Quote  
Join Date: Oct 2007
Posts: 6
Reputation: woozy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
woozy woozy is offline Offline
Newbie Poster

Re: Sort strings in lexicographical order but not to use built-in string functions

  #6  
Oct 21st, 2007
Hi iamthwee,

However, I solved the problem myself: http://www.daniweb.com/forums/post455234.html

The reason why I registered both forums is because I want to get as many thoughts as possible.

Just want to say, I'm a little bit "more" different than other "chumps", maybe not enough to let you Senior Posters (or so) to realize. After all, I know I am a noob to programming, but I'm eager to learn, that's enough for me.

Thank you for your opinion anyways.

Woozy
Last edited by woozy : Oct 21st, 2007 at 5:43 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 5:53 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC