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;

	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.

9 Years
Discussion Span
Last Post by woozy

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.


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.


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.