BEGIN
COMMENT THIS PROGRAM WILL SORT A VARIABLE NUMBER OF WORDS STORED ON
        AN INPUT FILE.  THE PROGRAM ACCEPTS THE NAME OF THE 
        FILE FROM THE CONSOLE AND OPENS THE FILE INDICATED.  IT
        THEN READS THE FIRST NUMBER IN THE FILE WHICH INDICATES
        HOW MANY NAMES ARE IN THE FILE. THIS NUMBER CAN CHANGE AS
        THE NUMBER OF NAMES IN THE FILE CHANGES.  THE PROGRAM THEN  
        READS IN THE WORDS AND STORES THEM IN AN ARRAY WHICH
        IS THEN SORTED AND PRINTED! ;


INTEGER I,N;
FILE INPUT; %NAME USED BY PROGRAM TO REFER TO A FILE%
STRING(15) FILENAME;%FILENAME UP TO 15 CHAR'S%
WRITE("INPUT NAME OF FILE TO BE SORTED:");
WRITE("USE WINPUT.INP FOR SAMPLE INPUT");
READ(FILENAME);  %READS FILENAME FROM CONSOLE%  
INPUT:=FILENAME; %THIS OPENS THE FILE%
READ INPUT(N);% READS NUMBER OF NAMES FROM FILE INPUT%
BEGIN
	STRING ARRAY WORDS[1:N];%MAX WORD SIZE EQUAL 10%
	FOR I:=1 STEP 1 UNTIL N DO
		READ INPUT(WORDS[I]);

	BEGIN
		PROCEDURE QUICKSORT;
                    BEGIN
			PROCEDURE SORT(L,R);
			 INTEGER L,R;
			 BEGIN
                         INTEGER I,J;
			   STRING X,W;
			   I:=L; J:=R;
			   X:=WORDS[(L+R)/2];
                           WHILE I<=J DO
			      BEGIN
				WHILE WORDS[I]< X DO I:= I+1;
				WHILE X<WORDS[J] DO J:=J-1;
			        IF  I<=J THEN
                                BEGIN
			   W:=WORDS[I]; WORDS[I]:=WORDS[J];
			   WORDS[J]:=W;
			   I:=I+1; J:=J-1;
			  END;
			END;
			IF L<J THEN SORT(L,J);
			IF L<R THEN SORT(I,R);
			END; %SORT%
			SORT(1,N);
		END; %QUICKSORT%

           % EXECUTION OF SORT BEGINS HERE %
		QUICKSORT;
                FOR I:=1 STEP 1 UNTIL N DO WRITE(WORDS[I]);
		END;
	END;
END
EOF
