Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
46
Task/Tree-traversal/Phix/tree-traversal.phix
Normal file
46
Task/Tree-traversal/Phix/tree-traversal.phix
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
constant VALUE = 1, LEFT = 2, RIGHT = 3
|
||||
|
||||
constant tree = {1, {2, {4, {7, 0, 0}, 0},
|
||||
{5, 0, 0}},
|
||||
{3, {6, {8, 0, 0},
|
||||
{9, 0, 0}},
|
||||
0}}
|
||||
|
||||
procedure preorder(object tree)
|
||||
if sequence(tree) then
|
||||
printf(1,"%d ",{tree[VALUE]})
|
||||
preorder(tree[LEFT])
|
||||
preorder(tree[RIGHT])
|
||||
end if
|
||||
end procedure
|
||||
|
||||
procedure inorder(object tree)
|
||||
if sequence(tree) then
|
||||
inorder(tree[LEFT])
|
||||
printf(1,"%d ",{tree[VALUE]})
|
||||
inorder(tree[RIGHT])
|
||||
end if
|
||||
end procedure
|
||||
|
||||
procedure postorder(object tree)
|
||||
if sequence(tree) then
|
||||
postorder(tree[LEFT])
|
||||
postorder(tree[RIGHT])
|
||||
printf(1,"%d ",{tree[VALUE]})
|
||||
end if
|
||||
end procedure
|
||||
|
||||
procedure level_order(object tree, sequence more = {})
|
||||
if sequence(tree) then
|
||||
more &= {tree[LEFT],tree[RIGHT]}
|
||||
printf(1,"%d ",{tree[VALUE]})
|
||||
end if
|
||||
if length(more) > 0 then
|
||||
level_order(more[1],more[2..$])
|
||||
end if
|
||||
end procedure
|
||||
|
||||
puts(1,"\n preorder: ") preorder(tree)
|
||||
puts(1,"\n inorder: ") inorder(tree)
|
||||
puts(1,"\n postorder: ") postorder(tree)
|
||||
puts(1,"\n level-order: ") level_order(tree)
|
||||
Loading…
Add table
Add a link
Reference in a new issue