I posted what you need to do the qsort method a while back....here it is
again....this version sorts alphabetically...simple change to make it by
level....

int comparedescs(const void *d1, const void *d2)
{
    typedef DESCRIPTOR_DATA DD;
    return strcmp((*(DD **)d1)->character->name, (*(DD
**)d2)->character->name);
}

void do_whotest(CHAR_DATA *ch, char *argument)
{
    DESCRIPTOR_DATA *d, *list[50];
    int x, cnt;

    for(cnt = 0, d = descriptor_list; d; d = d->next, cnt++)
    {
        if(d->character)
            list[cnt] = d;
    }

    send_to_char("Before sort:\n\r", ch);
    for(x = 0; x < cnt; x++)
        printf_to_char(ch, "%s\n\r", list[x]->character->name);

    qsort(list, cnt, sizeof(DESCRIPTOR_DATA *), comparedescs);

    send_to_char("\n\rAfter sort:\n\r", ch);
    for(x = 0; x < cnt; x++)
        printf_to_char(ch, "%s\n\r", list[x]->character->name);
}

Cam

----- Original Message -----
From: "Jeremy Hill" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Sunday, July 14, 2002 12:12 AM
Subject: Re: hack way of sorting who list by level


> http://www.the-infinite.org/lists/romlist/2000/01/msg00221.html
>
> Opinion:
> Would the above be an acceptable place to start on sorting characters for
who?
>
> I think it looks very promising.
>
>
> ----- Original Message -----
> From: "Cameron Matthews-Dickson" <[EMAIL PROTECTED]>
> To: "Jeremy Hill" <[EMAIL PROTECTED]>
> Sent: Saturday, July 13, 2002 7:12 PM
> Subject: Re: hack way of sorting who list by level
>
>
> > Well,
> >     A sorted linked-list would be faster as far as outputting the who
list
> > since all you'd have to do is iterate through it.  Doing the qsort would
> > mean putting the descriptor_list into an array and then calling qsort on
it
> > which would be a little slower.  Having a sorted linked list is a little
> > slower for insertions....both options would be better than your current
> > solution, I would think....
> >
> > Cam
> >
> >
> > ----- Original Message -----
> > From: "Jeremy Hill" <[EMAIL PROTECTED]>
> > To: <[email protected]>
> > Sent: Saturday, July 13, 2002 7:25 PM
> > Subject: hack way of sorting who list by level
> >
> >
> > > Based on:
> > >
> > > int i;
> > > for (i = 1; i <= MAX_LEVEL; i++)
> > > {
> > >     for ( d = descriptor_list; d != NULL; d = d->next )
> > >     {
> > >         CHAR_DATA *wch;
> > >         ...
> > >         (wch to descriptor)
> > >         ...
> > >         if (wch->level == i)
> > >             print_to_who(wch);
> > >    }
> > > }
> > >
> > > I figure this will work, but on a MUD with 310 levels and just 10
people
> > on, it
> > > would generate 3,100 loops.
> > >
> > > A couple of questions:
> > > 1. In your expert opinion, is this a miserable way to do it?  Pros?
Cons?
> > I
> > > figure sorting or qsorting the linked list of characters would be
better.
> > >
> > > 2. Would it be easier to add players to the list of players on connect
so
> > they
> > > are automatically sorted by level?
> > >
> > >
> > > --
> > > ROM mailing list
> > > [email protected]
> > > http://www.rom.org/cgi-bin/mailman/listinfo/rom
> > >
>
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
>

Reply via email to