Re: Append to list
From: Pere Montolio (tmp123_at_menta.net)
Date: 08/12/04
- Previous message: Pere Montolio: "Re: How to return clause in findall/3"
- In reply to: rhapsody: "Append to list"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 12 Aug 2004 00:29:24 -0700
See inserted comments. Hope they useful.
"rhapsody" <blurrynight@yahoo.com> wrote in message news:<7da0d8e77547715970941e3e9173d4a7@localhost.talkaboutprogramming.com>...
> 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),
Two times T? It is not best T1 and T2 and append(T1,T2,T)?
> write("Node : ", Name),
Better: write("Node : "), write(Name), nl,
> H = Name,
> nl.
>
> postOrder(btree(Name,nil,nil), [H|T]) :-
> write("Node : ",Name),
> H = Name,
> nl.
T is free here. [H|T] must be changed by [H]?
>
> 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
- Previous message: Pere Montolio: "Re: How to return clause in findall/3"
- In reply to: rhapsody: "Append to list"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|