home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format 92
/
af092a.adf
/
af92.lzx
/
ARexx_Code
/
tree_sort.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1996-10-30
|
1KB
|
81 lines
/* ---------------------------------------------- */
/* tree_sort.rexx - binary sort tree example code */
ROOT=1
tree.=0
word.=''
text='just a small piece of example text'
count=Words(text)
tree.ROOT
do i=1 to count
word.i=Word(text,i)
end
do i=2 to count
call BuildTree(i,ROOT)
end
call PrintTree(ROOT)
exit
/* ---------------------------------------------- */
BuildTree: Procedure expose tree. word.
parse arg i, node
if Upper(word.i)<=Upper(word.node) then
do
if tree.node.left=0 then tree.node.left=i
else call BuildTree(i,tree.node.left)
end
else do
if tree.node.right=0 then tree.node.right=i
else call BuildTree(i,tree.node.right)
end
return
/* ---------------------------------------------- */
PrintTree: Procedure expose tree. word.
parse arg node
if node ~=0 then
do
call PrintTree(tree.node.left)
say word.node
call PrintTree(tree.node.right)
end
return
/* ---------------------------------------------- */