delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/04/27/03:23:39

Date: Tue, 27 Apr 1999 10:21:23 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Seth Jones <seth AT kansmen DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Question: Linked lists and classes: Self initiation
In-Reply-To: <MPG.118e56767e41ca9c9896f7@client.sw.news.psi.net>
Message-ID: <Pine.SUN.3.91.990427102102.18849I-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Mon, 26 Apr 1999, Seth Jones wrote:

> The typical C++ definition of a linked list is something like
> 
> struct node
> {
>    type value;
>    node *next;
> };

Actually, it's usually the other way around:

  struct node
  {
    struct node *next;
    type value;
  };

The reason for this is that the first struct member has an offset of
zero, so node->next is the same as *node, and most compilers know
about this and optimize the code accordingly.  Such optimizations can
speed things significantly when you have a large list to scan.

> Only if I was rewriting it in LISP, or some other functional language. 
> C++ generally handles iteration more efficiently than recursion (I think 
> I mentioned that before). 

Actually, the Lisp dialects I've seen handle iteration more efficiently
than recursion as well.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019