W3C home > Mailing lists > Public > www-lib@w3.org > April to June 2000

RE: do I really understand this or not ?

From: Desrochers, Gary <Gary.Desrochers@fmr.com>
Date: Thu, 8 Jun 2000 16:11:00 -0400
Message-ID: <706274F62639D411A69200508BCF03AC21D885@MSGMMK577NTS.fmr.com>
To: "'Gregory Nicholls'" <gnicholls@level8.com>, www-lib@w3.org
No, the routine is right.  The HTList is in backwards order so that the
first item in the list is at the end of the chain.  The last item in the
list is the first in the chain.  (Unless it was sorted.)  While there is
extraneous code, the code is right.  It looks like it is copied from the
HTList_removeFirstObject routine above it.  If you remove the extraneous
stuff you get:
PUBLIC void * HTList_firstObject  (HTList * me)
{
    if (me && me->next) {
        while (me->next)
            me = me->next;
        return me->object;
    } else
        return NULL;
}

Your routine is actually returning the last object in the list.  This would
be the routine which does not exist called HTList_lastObject:
PUBLIC void * HTList_lastObject  (HTList * me)
{
    if (me && me->next)
     {
      return me->next->object;
     }
    return NULL;
}
-----Original Message-----
From: Gregory Nicholls [mailto:gnicholls@level8.com]
Sent: Thursday, June 08, 2000 3:00 PM
To: www-lib@w3.org
Subject: do I really understand this or not ?


Hi,
 I've found something odd with the HTList_firstObject() function. My
read on this is that it should return a pointer to the first object in
the list. Running some tests shows that this doesn't happen.
  After looking at the source it seems (to my naive eye) that this
routine will always return NULL.
    Here's the source I have with a mod that I put in to make it work
the way I _think_ it's supposed to.
Could someone more knowledgable please comment on this please ?

    Thanks,
        G
--------------- snip -----------------------
PUBLIC void * HTList_firstObject  (HTList * me)
{
/* This is the original code
    if (me && me->next) {
        HTList * prevNode;
        while (me->next) {
            prevNode = me;
            me = me->next;
        }
        return me->object;
    } else
        return NULL;
*/
/* This is my new stuff */
    if (me && me->next)
     {
      return me->next->object;
     }
    return NULL;
}
Received on Thursday, 8 June 2000 16:11:51 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 23 April 2007 18:18:36 GMT