Hello,
I've attempted to sort a double linked list, alphabetically by its member 'name' which is a character string, and it doesn't seem to work. It either goes into an endless loop, or it sorts them around, and puts em back in their original order. I used a typical bubble sort, and it worked fine in an array of character strings, but I suppose it doesn't work well for a linked list.
Heres the code I used:
Could someone please enlighten me on a way that will actually work? Or tell me if I made a stupid mistake? Thanks.Code:COMMAND_DATA *cmd, *cmd2, *temp; for(cmd=first_command;cmd!=NULL;cmd=cmd->next){ for(cmd2=first_command;cmd2!=NULL;cmd=cmd2->next){ if(cmd->name<cmd2->name){ temp=cmd; cmd=cmd2; cmd2=temp; } } }