Member Avatar for woozyking

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.

Recommended Answers

All 5 Replies

Member Avatar for woozyking

Lol, Salem, you caught me right over here, eh?

Member Avatar for iamthwee

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.

Member Avatar for woozyking

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.