Append to list

From: rhapsody (blurrynight_at_yahoo.com)
Date: 08/12/04


Date: Wed, 11 Aug 2004 20:17:02 -0400

Can anybody give me clues of what is the correct way of appending node's
name to the output slist during the recursion of postOrder/2? I have
difficulties in getting the logic right. Below is the codes. Thanks!
Domains
btreeType = nil; btree(string, btreeType, btreeType)
slist = string*

Predicates
nondeterm postOrder(btreeType, slist)
buildtree(btreeType)

Clauses
postOrder(btree(Name,Tree1,Tree2), [H|T]) :-
postOrder(Tree1,T),
postOrder(Tree2,T),
write("Node : ", Name),
H = Name,
nl.

postOrder(btree(Name,nil,nil), [H|T]) :-
write("Node : ",Name),
H = Name,
nl.

buildtree(Atree):-
T1 = btree(a, nil, nil),
T2 = btree(c, nil, nil),
T3 = btree(e, nil, nil),
T4 = btree(b, T1, T2),
Atree = btree(d, T4, T3).

Goal
buildTree(Atree),postOrder(Atree,List),write("List : ", List).

Regards,
Stanly



Relevant Pages

  • Re: Ugly loop
    ... > NIL ... LOOP may be overestimated. ... * May require one to combine multiple concepts like IF, PROGN, FUNCALL ... * May have recursion problems. ...
    (comp.lang.lisp)
  • Re: Iteration in lisp
    ... demonstrate the point that the recursion is finite and thus ... whether state3 throws to state1 or calls state1. ... 2: (STATE3 NIL) ... 1: returned NIL ...
    (comp.lang.lisp)
  • Remove every atom
    ... I'm still new to Lisp. ... still having lots of difficulties with recursion. ... (defun delete-in (e l) ...
    (comp.lang.lisp)
  • Remove every atom
    ... I'm still new to Lisp. ... still having lots of difficulties with recursion. ... (defun delete-in (e l) ...
    (comp.lang.lisp)
  • Re: Newbie-solved a problem in ANSI common lisp
    ... vishy wrote: ... Define this function using recursion, iteration, mapcar." ... Inefficient, needs two args. ... ((NIL NIL T T)) ...
    (comp.lang.lisp)