Hi Peter,

if you want to traverse the tree and place its elements in a list, you must
to consider the inductive definition of trees:

<tree> = nil  | tree(info:<number> left: <tree> right : <tree>)

according to this definition, your procedure should consider when the tree
is nil, in this case should return nil, when the tree has the form tree(...)
the procedure should put in a list tree.info and call recursively el
procedure passing it the left subtree (tree.left) and the right subtree
(tree.right), something like:

{Append {Order Tree.left} {Append [Tree.info] {Order Tree.right}}}

I hope to help you and to be clear.

Bye.

2010/10/1 Peter Breitsprecher <[email protected]>

> First, I would like to thank everyone for the help they have given me while
> working my assignments.  It has been extremely helpful, I got both programs
> working with minor nuances, but as I get better and learn more about this
> language i'm sure it will come more naturally to me.
>
> Now i'm dealing with trees.
>
> I understand how browse the tree, but I'm not sure how to traverse the tree
> properly...
>
> Given this binary tree as a record,
>
> T=tree(info:10
>        left:tree(info:7
>          left:nil
>          right:tree(info:9
>                 left:nil
>                 right:nil))
>        right:tree(info:18
>           left:tree(info:14
>                 left:nil
>                 right:nil)
>           right:nil))
>
> {I can browse to all the values {Browse T.left.info} etc...
>
> So I wrote this, which the machine accepts.
>
> fun {Order X}
>    if X.left == nil then nil
>    else X.info|{Order X.left}
>       if X.right == nil then nil
>       else X.info|{Order X.right}
>       end
>    end
> end
>
> I wanted to Check to see if the left of the tree is nil, if yes, then I
> wanted to check the right side of the tree, to see if that was nil.  If it
> isn't nil, then I wanted to take the value in that position and place it in
> a list and then browse the rest of the tree to the left and the the right.
> I know the code doesn't work, but can someone point me in the right
> direction and explain how to actually browse the tree without giving me
> code?  I'll learn more if I do it with guidance instead of having the code
> given to me.
>
> Thank you all again for the help so far....
> --
>
>
> Kurt Breitsprecher
> (807) 474-9601
> [email protected]
>
>
>
> _________________________________________________________________________________
> mozart-users mailing list
> [email protected]
> http://www.mozart-oz.org/mailman/listinfo/mozart-users
>



-- 
Carlos Ramírez
Ingeniero de Sistemas
Universidad del Valle
Cali - Colombia
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users
  • Trees Peter Breitsprecher
    • Re: Trees Carlos Ramirez

Reply via email to