REM ... QUICKSORT ... FOR ALPHABETICAL SORTS ...
REM
REM ... WRITTEN BY: EDWARD A. VALENZUELA
REM                 JANUARY 25, 1982
REM
REM --------------------------------------------------------------------
REM
REM   VARIABLES:
REM		
REM	SL(P) ... THE LEFT END OF THE NEXT SUBLIST
REM     SR(P) ... THE RIGHT END OF THE NEXT SUBLIST
REM 	I ....... INDEX VARIABLE FOR THE LEFT SIDE OF LIST
REM     L  ...... LEFT END OF THE CURRENT LIST
REM	J ....... INDEX VARIABLE FOR THE RIGHT SIDE OF LIST
REM	R  ...... RIGHT END OF THE CURRENT LIST
REM 	S ....... DIRECTION SWITCH (-1 AT I, +1 AT J)
REM	T ....... TEMPORARY EXCHANGE VARIABLE
REM 	X( ) .... LIST OF NUMBERS TO BE SORTED
REM	P ....... POINTER TO THE TOP OF THE STACK OF SUBLISTS
REM	
REM --------------------------------------------------------------------

1550 REM
DIM SL%(20),SR%(20)

P% = 1
SL%(1) = 1
SR%(1) = N%

WHILE P%>0
  L%=SL%(P%)
  R%=SR%(P%)
  P%=P%-1
      WHILE L% < R%
        I% = L% 
        J% = R% 
        S% = -1 
            WHILE I% < J% 
              IF X$(KODE%(I%)) > X$(KODE%(J%)) THEN \
                T% = KODE%(I%) : \
                KODE%(I%) = KODE%(J%) : \
                KODE%(J%) = T% : \
              S% = SGN(-S%)
              IF S% = 1 THEN I%=I%+1 ELSE J%=J%-1
            WEND
        IF I%+1 < R% THEN
          P% = P% + 1 : \
          SL%(P%) = I% + 1 : \
          SR%(P%) = R%  
        R% = I% - 1
      WEND
WEND

RETURN
