Tree traversal You are encouraged to solve this task according to the task description, using any language you may know. Implement a binary tree where each node carries an integer, and implement preoder, inorder, postorder and level-order traversal . Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / / \ 7 8 9 The correct output should look like this: preorder: 1 2 4 7 5 3 6 8 9 inorder: 7 4 2 5 1 8 6 9 3 postorder: 7 4 5 2 8 9 6 3 1 level-order: 1 2 3 4 5 6 7 8 9 This article has more information on traversing trees. Contents (if (endp tree) (flatten-level-r1 levels)))))) (if (zp (1+ max-level)) (flatten-level-r2 levels (len levels)))) type Node is record begin Temp : Node_Access := new Node; use Queues; Node_Queue : List; Next : Node_Access; - note the strong code structural similarities with C. Note the changes from the original translation from C in this diff .
Read full article from Tree traversal - Rosetta Code
No comments:
Post a Comment