CompuServe Thread

ARexx Sort

6 messages in this thread
#30468From: Matthew J. W. RatcliffDec 1, 1992 6:10 PM
I would like to sort a list in ARexx, I thought there was a fn for this already, but can't find it. I am about to send the list to a temp. file, then use dos sort on it.. Anybody have a more elegant solution? (no I don't care to write a sort that will be longer than the program)
#30478From: Greg GivlerDec 2, 1992 3:34 PM
That is probably the easiest way, I wrote a bubble sort in AREXX once, but found that using AmigaDOS sort is much faster and easier. If all you need is to find the largest number or smallest number look at MAX() and MIN(). Greg Greg Givler – CBMSER Sysop Commodore Product Assurance
#30498From: Matthew J. W. RatcliffDec 4, 1992 12:02 PM
I'm processing a list of filenames… I think the results would look better sorted.. I guess its dos sort then! thanks
#30663From: Frank RobertsDec 9, 1992 7:09 PM
Arnie, Here's a rexx shellsort routine from the latest book THE AREXX COOKBOOK by Merrill Callaway. I highly recommend the book. Hope this routine helps. /* shellsort.rexx input the file for sorting */ PARSE UPPER ARG infile' 'outfile IF infile = '' THEN DO SAY 'Input sort filename and path: ' PARSE PULL infile END RC=OPEN('sortfile',infile,'READ') IF ~RC THEN DO SAY 'File not opened. Separate arguments with space no comma.' EXIT END k=1 DO WHILE ~EOF('sortfile') list.k=READLN('sortfile') k=k+1 END listlength = k-2 SAY listlength 'entries to sort…' /* The Shell Sort */ RC=TIME('R') span = 1 DO WHILE (span < listlength); span = span * 2; END DO WHILE (span > 1) span = span % 2 numpairs = listlength – span DO node = 1 TO numpairs nextnode = node + span IF list.node > list.nextnode THEN DO store = list.nextnode list.nextnode = list.node DO bubpos = node-span TO 1 BY -span WHILE (store < list.bubpos) nextnode = bubpos + span list.nextnode = list.bubpos END bubpos bubpos = bubpos + span list.bubpos = store END END node END SAY 'Elapsed time='TIME('E')' seconds.' /* output results */ IF outfile = '' THEN DO SAY 'Specify filename and path for sorted output.' PARSE PULL outfile IF outfile='' THEN DO SAY 'No output written.' EXIT 5 END END CALL OPEN('outfile',outfile,'WRITE') DO i=1 TO listlength CALL WRITELN('outfile',list.i) END i SAY 'Output has been written to 'outfile EXIT 0
#30866From: Matthew J. W. RatcliffDec 17, 1992 1:33 PM
Thanks! I just got that book, and haven't had a chance to go through it yet. I also got a new ARexx version with a sort server included… so many options…
#30918From: Art SteinmetzDec 21, 1992 2:07 PM
The sort server is very good. It uses a "quicksort" algorithm and since it's compiled will be quicker than anything in AREXX itself. — Art