Anonymous user
Tree traversal: Difference between revisions
m
→{{header|REBOL}}: renamed second and third with left and right
m (→{{header|REBOL}}: added visit func) |
m (→{{header|REBOL}}: renamed second and third with left and right) |
||
Line 8,986:
visit: func [tree [block!]][prin rejoin [first tree " "]]
left: :second
right: :third
preorder: func [tree [block!]][
if not empty? tree [visit tree]
attempt [preorder
attempt [preorder
]
prin "preorder: " preorder tree
Line 8,996 ⟶ 8,998:
inorder: func [tree [block!]][
attempt [inorder
if not empty? tree [visit tree]
attempt [inorder
]
prin "inorder: " inorder tree
Line 9,004 ⟶ 9,006:
postorder: func [tree [block!]][
attempt [postorder
attempt [postorder
if not empty? tree [visit tree]
]
Line 9,020 ⟶ 9,022:
tree: dequeue queue
if not empty? tree [visit tree]
attempt [enqueue
attempt [enqueue
]
]
|