home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 92 / af092a.adf / af92.lzx / ARexx_Code / tree_sort.rexx < prev    next >
OS/2 REXX Batch file  |  1996-10-30  |  1KB  |  81 lines

  1. /* ---------------------------------------------- */
  2.  
  3. /* tree_sort.rexx - binary sort tree example code */
  4.  
  5. ROOT=1
  6.  
  7. tree.=0
  8.  
  9. word.=''
  10.  
  11. text='just a small piece of example text'
  12.  
  13. count=Words(text)
  14.  
  15. tree.ROOT
  16.  
  17. do i=1 to count
  18.  
  19.   word.i=Word(text,i)
  20.         
  21. end
  22.  
  23. do i=2 to count
  24.    
  25.   call BuildTree(i,ROOT)
  26.         
  27. end
  28.         
  29. call PrintTree(ROOT)
  30.  
  31. exit
  32.  
  33. /* ---------------------------------------------- */
  34.  
  35. BuildTree: Procedure expose tree. word.
  36.  
  37. parse arg i, node
  38.  
  39. if Upper(word.i)<=Upper(word.node) then
  40.  
  41.          do
  42.    
  43.            if tree.node.left=0 then tree.node.left=i
  44.    
  45.            else call BuildTree(i,tree.node.left)
  46.    
  47.          end
  48.    
  49.   else   do
  50.    
  51.            if tree.node.right=0 then tree.node.right=i
  52.    
  53.            else call BuildTree(i,tree.node.right)
  54.    
  55.          end   
  56.  
  57. return    
  58.  
  59. /* ---------------------------------------------- */
  60.  
  61. PrintTree: Procedure expose tree. word.
  62.  
  63. parse arg node
  64.  
  65. if node ~=0 then
  66.  
  67.         do
  68.         
  69.           call PrintTree(tree.node.left)
  70.         
  71.           say word.node
  72.         
  73.           call PrintTree(tree.node.right)
  74.         
  75.         end
  76.        
  77. return
  78.         
  79. /* ---------------------------------------------- */
  80.  
  81.