Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDENTIFICATION DIVISION.
- PROGRAM-ID. QSORT RECURSIVE.
- DATA DIVISION.
- LOCAL-STORAGE SECTION.
- 01 I-IZ INDEX.
- 01 I-DE INDEX.
- 01 A INDEX.
- 01 B INDEX.
- 01 AUX PIC 9.
- LINKAGE SECTION.
- 01 PRIMERO INDEX.
- 01 ULTIMO INDEX.
- 01 ARRAY.
- 05 ELEMENTO PIC 9 OCCURS 10.
- PROCEDURE DIVISION USING BY REFERENCE ARRAY, PRIMERO, ULTIMO.
- MAIN-PROCEDURE.
- SET I-IZ TO PRIMERO.
- SET I-DE TO ULTIMO.
- IF PRIMERO < ULTIMO
- PERFORM UNTIL I-IZ NOT < I-DE
- PERFORM UNTIL ELEMENTO(I-IZ) NOT < ELEMENTO(ULTIMO) OR I-IZ = I-DE
- SET I-IZ UP BY 1
- END-PERFORM
- PERFORM UNTIL ELEMENTO(I-DE) NOT > ELEMENTO(ULTIMO) OR I-IZ = I-DE
- SET I-DE DOWN BY 1
- END-PERFORM
- SET A TO I-IZ
- SET B TO I-DE
- PERFORM SWAP
- END-PERFORM
- SET A TO I-IZ
- SET B TO ULTIMO
- PERFORM SWAP
- SET I-IZ DOWN BY 1
- SET I-DE UP BY 1
- CALL 'QSORT' USING ARRAY, PRIMERO, I-IZ
- CALL 'QSORT' USING ARRAY, I-DE, ULTIMO
- END-IF.
- GOBACK.
- SWAP.
- MOVE ELEMENTO(A) TO AUX.
- MOVE ELEMENTO(B) TO ELEMENTO(A).
- MOVE AUX TO ELEMENTO(B).
- END PROGRAM QSORT.
Add Comment
Please, Sign In to add comment