dos_compilers/RHA (Minisystems) ALGOL v55/QSORT.ALG
2024-07-06 09:53:43 -07:00

32 lines
922 B
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'BEGIN''ARRAY' A[1:100];
'INTEGER' I,N,INDEV;
'PROCEDURE' QSORT(ARR,LOW,HIGH); 'VALUE' LOW,HIGH;
'ARRAY' ARR; 'INTEGER'LOW,HIGH;
'IF' LOW<HIGH 'THEN'
'BEGIN''INTEGER' TOP,BOTTOM; 'REAL' X;
BOTTOM:=LOW-1; TOP:=HIGH;
LOOP1: BOTTOM:=BOTTOM+1;
'IF' ARR[BOTTOM]<ARR[HIGH] 'THEN''GOTO' LOOP1;
LOOP2: TOP:=TOP-1;
'IF' ARR[TOP]>=ARR[HIGH] 'AND' TOP>BOTTOM
'THEN''GOTO' LOOP2;
'IF' TOP>BOTTOM 'THEN'
'BEGIN' X:=ARR[TOP]; ARR[TOP]:=ARR[BOTTOM];
ARR[BOTTOM]:=X; 'GOTO' LOOP1;
'END';
X:=ARR[HIGH]; ARR[HIGH]:=ARR[BOTTOM]; ARR[BOTTOM]:=X;
QSORT(ARR,LOW,BOTTOM-1); QSORT(ARR,BOTTOM+1,HIGH);
'END' QSORT;
START: IOC(4); INDEV:=INPUT; 'IF' INDEV<0 'THEN''GOTO' START;
N:=READ(INDEV); 'FOR' I:=1 'STEP' 1 'UNTIL' N 'DO'
A[I]:=READ(INDEV);
QSORT(A,1,N);
'FOR' I:=1 'STEP' 1 'UNTIL' N 'DO'
'BEGIN' RWRITE(1,A[I],8,0);
'IF' I=I%5*5 'THEN' SKIP(1);
'END';
CLOSE(INDEV); 'GOTO' START;
'END''FINISH'