
%BEGIN
%constinteger n=10
%OWNSTRING(31)%ARRAY NAMES(0:n)="","ZULU,Z","BLOGGS,A","BLOGGS,Q",
            "STEPHENS,P","STEPHENS,F","MCLEOD,R","MACLEOD,R","SMITH,F","KNOTT,A","TRUEMAN,F"
%ROUTINESPEC STRINGSORT(%STRINGARRAYNAME X,%INTEGER F,T)
%INTEGER I
      STRINGSORT(NAMES,1,N)
         %if names(1)="BLOGGS,A" %and names(5)="MCLEOD,R" %and names(n)="ZULU,Z" %c
         %then printstring("TEST OK") %and %stop
      PRINTSTRING(NAMES(I).TOSTRING(NL)) %FOR I=1,1,N
%ROUTINE STRINGSORT(%STRINGARRAYNAME X,%INTEGER FROM,TO)
%INTEGER L,U
%STRING(255)D
      %RETURN %IF FROM>=TO;             ! NOTHING (LEFT) TO SORT
      L=FROM; U=TO
      D=X(U);                           ! THE PARTITION BOUND
      %CYCLE
         L=L+1 %WHILE L<U %AND D>X(L)
         %EXIT %IF L>=U
         X(U)=X(L);                                                          
         U=U-1 %WHILE L<U %AND X(U)>D
         X(L)=X(U)
      %REPEAT %UNTIL L>=U
      X(U)=D
      L=L-1; U=U+1
      STRINGSORT(X,FROM,L) %IF  FROM<L
      STRINGSORT(X,U,TO) %IF TO>U
%END
%ENDOFPROGRAM
