Help With Lisp Code for a Binary Tree

Posted by iulia on Stack Overflow See other posts from Stack Overflow or by iulia
Published on 2010-05-14T17:27:48Z Indexed on 2010/05/15 5:34 UTC
Read the original article Hit count: 297

Filed under:
|
I have

    (setq l2 '(1 (2 b (c 1 b))(a (1 2) d)))

    ( defun drumuri (l3) 
    ( cond ( (atom l3) ( cons l3 nil))
         ( t ( append ( cons ( car l3 ) nil)
                ( drumuri ( cadr l3))
                 (cons (car l3)nil)
                 ( drumuri ( caddr l3))
                     ))))
    ( drumuri l2)

and it gives me:

 Break 2 
[4]>     DRUMURI
 Break 2 
[4]>     (1 2 B 2 C 1 C B 1 A 1 2 1 NIL A D)

but i need:

     ((1 2 B)(1 2 C 1)(1 2 C B)(1 A 1 2)(1 A D)) 

© Stack Overflow or respective owner

Related posts about clisp

Related posts about binary-trees