home *** CD-ROM | disk | FTP | other *** search
/ Share Gallery 1 / share_gal_1.zip / share_gal_1 / UT / UT070.ZIP / MENUS.EXE / SORT.MNU < prev    next >
Text File  |  1991-03-25  |  1KB  |  54 lines

  1. Comment
  2. ==========================================================
  3.  
  4. QuickSort program written in MarxMenu. Works like DOS sort
  5. program. This shows parameter passing and recursive
  6. programming.
  7.  
  8. Usage: DIR|MARXMENU SORT|MORE
  9.        MARXMENU SORT INFILE OUTFILE
  10.  
  11. ==========================================================
  12. EndComment
  13.  
  14. ClearScreenOnExit Off
  15.  
  16. var SortBuf Middle
  17.  
  18.  
  19. ReadTextFile  (ParamStr(2),SortBuf)
  20.  
  21. Sort(1,NumberOfElements(SortBuf))
  22.  
  23. WriteTextFile (ParamStr(3),SortBuf)
  24.  
  25.  
  26. Procedure Sort (L,R)
  27. var I,J,Swap
  28.    I = L
  29.    J = R
  30.    Middle = SortBuf[(L+R)/2]
  31.    repeat
  32.       while SortBuf[I] < Middle
  33.          I = I + 1
  34.       endwhile
  35.       while Middle < SortBuf[J]
  36.          J = J - 1
  37.       endwhile
  38.       if I <= J
  39.          Swap = SortBuf[J]
  40.          SortBuf[J] = SortBuf[I]
  41.          SortBuf[I] = Swap
  42.          I = I + 1
  43.          J = J - 1
  44.       endif
  45.    until I > J
  46.    if (J - L) < (R - I)
  47.       if L < J then Sort(L,J);
  48.       if I < R then Sort(I,R);
  49.    else
  50.       if I < R then Sort(I,R);
  51.       if L < J then Sort(L,J);
  52.    endif
  53. EndProc
  54.