50380 S.AL% = FILE.CTR% ' Limit of array to be sorted **** REQUIRED FOR SORT ****
50400 DIM S.SP%(CINT(LOG(S.AL%)/.346574),2) ' If sort is to be called more than once, `DIM' the stack `S.SP%' for the largest size of the array outside the sort
50440 SWAP FILE.NAME$(S.SL%),FILE.NAME$(S.LL%):IF S.SL% > S.UL%-2 THEN S.UL% = S.SL%-1 ELSE IF S.SL% < S.LL%+2 THEN S.LL% = S.LL%+1 ELSE S.IS% = S.IS%+1: S.SP%(S.IS%,1)=S.LL%: S.SP%(S.IS%,2) = S.SL%-1: S.LL%=S.SL%+1
50460 GOTO 50540
50480 FOR S.I1% = S.LL% + 1 TO S.UL%: FOR S.I2% = S.LL% TO S.I1%: IF FILE.NAME$(S.I1%) < FILE.NAME$(S.I2%) THEN SWAP FILE.NAME$(S.I1%),FILE.NAME$(S.I2%)
50500 NEXT S.I2%: NEXT S.I1%
50520 IF S.IS% = 0 THEN EXIT SUB ELSE S.LL% = S.SP%(S.IS%,1): S.UL%=S.SP%(S.IS%,2): S.IS% = S.IS%-1
50540 IF S.UL% - S.LL% <= 9 THEN 50480 ELSE S.LS% = S.LL%: S.US% = S.UL% + 1: SWAP FILE.NAME$(S.LL%),FILE.NAME$(INT((S.US%-S.LS%)/2)+S.LL%)
50560 IF S.US% = S.LS%+1 THEN S.SL% = S.LS%: GOTO 50440 ELSE S.LS% = S.LS% + 1: IF FILE.NAME$(S.LS%) <= FILE.NAME$(S.LL%) THEN 50600
50580 IF S.US% = S.LS% + 1 THEN S.SL% = S.LS%-1: GOTO 50440 ELSE S.US% = S.US% - 1: IF FILE.NAME$(S.US%) >= FILE.NAME$(S.LL%) THEN 50580 ELSE SWAP FILE.NAME$(S.LS%),FILE.NAME$(S.US%): GOTO 50560
50600 IF S.US% = S.LS% + 1 THEN S.SL% = S.LS%: GOTO 50440 ELSE S.US% = S.US% - 1: IF FILE.NAME$(S.US%) >= FILE.NAME$(S.LL%) THEN 50560
50620 IF S.US% = S.LS% + 1 THEN S.SL% = S.US%: GOTO 50440 ELSE S.LS% = S.LS% + 1: IF FILE.NAME$(S.LS%) <= FILE.NAME$(S.LL%) THEN 50620 ELSE SWAP FILE.NAME$(S.LS%),FILE.NAME$(S.US%): GOTO 50600