Anonymous user
Same fringe: Difference between revisions
→version 1.1: comgined two subroutines into one, changed/added comments, used cardinal numbers instead of ordinal numbers for internal tree identifiers.
m (→version 1.1: removed OVERFLOW from the PRE html tagm, indented and changed section header comments.) |
(→version 1.1: comgined two subroutines into one, changed/added comments, used cardinal numbers instead of ordinal numbers for internal tree identifiers.) |
||
Line 1,699:
<br><br>This version has:
:::* elided a subroutine
:::* elided superfluous '''do ── end''' groups
:::* elided some stemmed array tails
:::* elided some REXX variables (lvl, debug, ···)
:::* simplified some stem names
:::* displays the tree (as an ASCII display)
:::* changed ''tree'' names so as to not conflict with ''leaf'' names
:::* uses non-case sensitive tree names
:::* used boolean based variables as ''logicals''
:::* expanded message texts
:::*
:::* streamlined the '''make_tree''' subroutine
<lang rexx>/*REXX
_=left('',28); say _ ' A A '
say _ ' / \ ◄────1st tree / \ '
Line 1,721 ⟶ 1,722:
say; #=0 /*#: # of leaves. */
parse var # done. 1 node. /*set all these variables to zero*/
call make_tree
call make_tree
z1=root.
z2=z1;
do # %
if L1==L2 then do
if L1==0 then call sayX 'The trees are equal.'
say ' The ' L1 " leaf is identical in both trees."
do until \done.
z1=go_next(z1,
end
done.
do until \done.
z2=go_next(z2,
end
done.
end
else select
when L1==0 then call sayX L2 'exceeds leaves in 1st tree'
when L2==0 then call sayX L1 'exceeds leaves in 2nd tree'
otherwise call sayX 'A difference is: ' L1 '¬=' L2
end /*select*/
end /*# % 2*/
exit
/*──────────────────────────────────GO_NEXT subroutine──────────────────*/
Line 1,763 ⟶ 1,764:
return next /*the next node (or 0, if done).*/
/*──────────────────────────────────MAKE_NODE subroutine────────────────*/
make_node: parse arg name,t;
q = node.t.0 + 1
node.t.q._Lson = 0 ;
return q /*number of the node just created*/
/*──────────────────────────────────MAKE_TREE subroutine────────────────*/
make_tree: procedure expose node. root. #; arg tree /*build a tree.*/
▲if tree=='1ST' then hhh='H'
/*quacks like a
return
/*──────────────────────────────────SAYX subroutine─────────────────────*/
sayX: say; say arg(1); say;
/*──────────────────────────────────SON subroutine──────────────────────*/
if q\==0 then do; node.t.q._dad=son; node.t.son.
node.t.dad.
▲if node.t.dad._Lson>0 then node.t.le._brother=node.t.dad._Rson
return</lang>
'''output'''
|