Anonymous user
Same fringe: Difference between revisions
m
→version 1.1: changed some comments, simplified some IF statements.
(→{{header|Tcl}}: Added zkl) |
m (→version 1.1: changed some comments, simplified some IF statements.) |
||
Line 1,710:
:::* combined subroutines '''attleft''' and '''attright''' into one
:::* streamlined the '''make_tree''' subroutine
<lang rexx>/*REXX program examines the leaves of two binary trees (as
_=left('',28); say _
say _
say _
say _
say _
say _
say _
say _
say _
say
call make_tree 1 /*define tree number 1 (1st tree)*/
call make_tree 2 /* " " " 2 (2nd " )*/
z1=root.1; L1=node.1.z1; done.1.z1=1 /*L1 is a leaf on tree number
z2=z1; L2=node.2.z2; done.2.z2=1 /*L2 " " " " "
do # % 2 /*loop for the number of leaves. */
if L1==L2 then do
if L1==0 then call sayX 'The trees are equal.'
say ' The ' L1 " leaf is identical in both trees."
done.1.z1=1
done.2.z2=1
end
Line 1,748:
exit
/*──────────────────────────────────GO_NEXT subroutine──────────────────*/
go_next: procedure expose node.;
next=
if node.t.q._Lson\==0
if next==
if next==
return next /*the next node (or 0, if done).*/
/*──────────────────────────────────MAKE_NODE subroutine────────────────*/
Line 1,769:
return q /*number of the node just created*/
/*──────────────────────────────────MAKE_TREE subroutine────────────────*/
make_tree: procedure expose node. root. #; parse arg tree
if tree==1 then hhh='H' /* [↓] must be a wood duck*/
else hhh='δ' /*the odd duck in the whole tree.*/
a=make_node('A', tree);
b=make_node('B', tree); call son 'L', b,a,tree
c=make_node('C', tree); call son 'R', c,a,tree
d=make_node('D', tree); call son 'L', d,b,tree
e=make_node('E', tree); call son 'R', e,b,tree
f=make_node('F', tree); call son 'L', f,c,tree
g=make_node('G', tree); call son 'L', g,d,tree
/*quacks like a duck?*/ h=make_node(hhh, tree); call son 'L', h,f,tree
i=make_node('I', tree); call son 'R', i,f,tree
return
/*──────────────────────────────────SAYX subroutine─────────────────────*/
Line 1,787:
son: procedure expose node.; parse arg ?,son,dad,t; LR = '_'?"SON"
node.t.son._dad=dad; q=node.t.dad.LR /*define which son [↑] */
if q\==0 then do; node.t.q._dad=son;
node.t.dad.LR=son
if ?=='R'
return</lang>
'''output'''
|