Re: what's the meaning of "car","cdr","cons" in tree's algorithm?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Anders Eriksson (anders.eriksson_at_morateknikutveckling.se)
Date: 04/20/04


Date: Tue, 20 Apr 2004 11:37:46 +0200

Hello!

On Tue, 20 Apr 2004 17:06:12 +0800, hostran wrote:
<snip>
> there is "/* address of <car> */" & "/* address of <cdr> */" , but I don't
> know what's the meanning of "car" , "cdr" & "cons"?
>

Whoa, a flashback from the days when I programmed in Lisp!

You can read more about this here:
http://www.delorie.com/gnu/docs/elisp-manual-21/elisp_25.html

To summarize (since I don't know exactly how the tree is created this is my
guess): cons is a struct that contains two pointer, The first pointer is
called 'car' and points to a cons on the left side of the tree and the
second pointer is called 'cdr' and points to a cons on the right side of
the tree.
(left and right side may be switched)

// Anders



Relevant Pages

  • Re: whats the meaning of "car","cdr","cons" in trees algorithm?
    ... a flashback from the days when I programmed in Lisp! ... > To summarize (since I don't know exactly how the tree is created this is ... cons is a struct that contains two pointer, ...
    (microsoft.public.vc.language)
  • Re: hacker challenge - traverse a list
    ... Here is a little challenge - print the contents of a binary tree ... I assume there are no up links, otherwise the algorithm is trivial. ... space hence unbounded number of bits in a pointer? ... Left branch *not* leaf, rotate: ...
    (comp.programming)
  • Re: question of style
    ... end of the day the quality of the code depends more on the quality of ... or the equivalent null pointer exceptions in Java, C, or whatever? ... But you have implemented a mutable tree. ...     def get: ...
    (comp.lang.python)
  • Re: Help me come up with a few and simple programming challenges
    ... >Dave Vandervies wrote: ... >> language, I'd probably pass around a pointer to the list's head pointer ... >(define (sublist tree lo hi) ...
    (comp.lang.scheme)
  • Re: Reading XML stream using unmanaged c++
    ... You don't need a back pointer to implement tree structures. ... but a back pointer is a handy thing to have when using a DOM node. ... XML is metadata, but an XML document is an XML metadata structure with actual data ...
    (microsoft.public.vc.mfc)