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.