inorder_dl(tree(X, L, R), Xs-Ys) :- inorder_dl(L, Xs-[X|Zs]), inorder_dl(R, Zs-Ys). inorder_dl(void, Xs-Xs). preorder_dl(tree(X, L, R), [X|Xs]-Ys) :- preorder_dl(L, Xs-Zs), preorder_dl(R, Zs-Ys). preorder_dl(void, Xs-Xs). postorder_dl(tree(X, L, R), Xs-Zs) :- postorder_dl(R, Ys-[X|Zs]), postorder_dl(L, Xs-Ys). postorder_dl(void, Xs-Xs).
Wednesday, November 15, 2006
Difference Lists for visiting trees (Prolog)
This is are some (simple) exercises in Prolog using difference lists.They should be correct, but I have to say I'm a beginner Prolog programmer... so...
Etichette:
Declarative Programming,
Functional Programming,
Prolog
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment