Date: Tue, 27 Apr 1999 10:21:23 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: Seth Jones cc: djgpp AT delorie DOT com Subject: Re: Question: Linked lists and classes: Self initiation In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk 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.