Mail Archives: djgpp/1999/04/27/03:23:39
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 -