The problem with that is that the skill_list is an array of skill_types,
whereas the help_first list is a linked list of pointers to help_data...
in order to sort those, you're going to need to use one of the sorting
algorithms taught in most CS-type classes, and it's been so long since I
took one, that the only one I can remember the name of is the bubble
sort, which is terribly inefficient from what I remember, but basically
you could do something like this:
HELP_DATA *help_prev, *help_next, *help_temp;
int count = 0;
for ( help_file = help_first, help_file; help_file = help_file->next )
count++;
for ( ; count > 0; count-- )
{
for ( help_prev = help_first, help_next = help_prev->next; help_prev
&& help_next; help_prev = help_next )
{
help_next = help_prev->next;
if ( help_prev == help_first )
{
if ( strcmp( help_prev->keyword, help_next->keyword ) > 0 )
// help_next comes before help_prev alphabetically
{
help_prev->next = help_next->next;
help_next->next = help_prev;
help_first = help_next;
}
}
else
{
if ( strcmp( help_prev->keyword, help_next->keyword ) > 0 )
// help_prev comes before help_next alphabetically
{
help_prev->next = help_next->next;
help_next->next = help_prev;
}
}
}
}
I don't promise that this will work, but it looks ok to me, like I said
tho, it's very inefficient, as it runs through the entire linked list as
many times as there are elements, flipping 2 elements if they're out of
order alphabetically, as the lower letters 'bubble' their way to the
top... since this doesn't need to be done very often, unless you go on a
spree adding help files and need to re-sort them, you could always put
it in with a #if defined(SORT_HELPS) precompiler option, so that it only
gets executed when you define that value... and please, if anyone else
out there has some more efficient sorting methods, throw them out there,
as I've long forgotten all of my own :D
Richard Lindsey
-----Original Message-----
From: Valnir [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 12, 2004 9:05 AM
To: [email protected]
Subject: Sorting.
Ok, a while back I was asking how to sort my skills. Well, I figured
that
all out and it's working great. I got a new sorting issue though. I want
to
sort my HELPS. This is a whole different arena. Tried using the same
thought
process.. BOOM.
My helps are in the 'struct help_data' and 'struct help_data HELP_DATA'
format. Any help would be great. (and of course they load on boot into
the
'help_first' etc format.)
- Valnir
--
ROM mailing list
[email protected]
http://www.rom.org/cgi-bin/mailman/listinfo/rom