Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
CBL NOSSRANGE
IDENTIFICATION DIVISION.
PROGRAM-ID. SEDET003.
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* COMB SORT WITH INDEXES
* By Glenn9999@tek-tips.com *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SORT-TABLE-ITEMS.
04 SORT-TABLE PIC 9(5) OCCURS 1 TIMES
INDEXED BY I
SWAP-NUMBER.
01 TEST-VARS.
04 IN-TIME PIC 9(8).
04 GEN-COUNTER PIC S9(5) COMP-3.
04 COUNTER-1 PIC S9(5) COMP-3.
04 COUNTER-2 PIC S9(5) COMP-3.
01 SORT-PROC-VARS.
04 SWAP-VALUE PIC 9(5).
04 JUMP-SIZE PIC S9(5) COMP-3.
04 TABLE-SIZE PIC S9(5) COMP-3.
04 UPPER-LIMIT PIC S9(5) COMP-3.
04 TABLE-RIGHT PIC S9(5) COMP-3 VALUE 1000.
04 SWAP PIC X.
*----------------------------------------------------------------
PROCEDURE DIVISION.
0000-START-SECTION.
ACCEPT IN-TIME FROM TIME.
DISPLAY "BEFORE: " IN-TIME.
PERFORM VARYING GEN-COUNTER FROM 1 BY 1 UNTIL GEN-COUNTER > 1
MOVE 1 TO COUNTER-1
PERFORM VARYING COUNTER-2 FROM 1
BY -1 UNTIL COUNTER-2 < 1
MOVE COUNTER-2 TO SORT-TABLE (COUNTER-1)
ADD 1 TO COUNTER-1
END-PERFORM
PERFORM 1000-QUICKSORT
END-PERFORM.
ACCEPT IN-TIME FROM TIME.
DISPLAY "AFTER: " IN-TIME.
* PERFORM 0600-DISPLAY.
GOBACK.
0600-DISPLAY SECTION.
PERFORM VARYING GEN-COUNTER FROM 1 BY 1 UNTIL GEN-COUNTER > 1
DISPLAY GEN-COUNTER ': ' SORT-TABLE (GEN-COUNTER)
END-PERFORM.
1000-QUICKSORT SECTION.
MOVE TABLE-RIGHT TO TABLE-SIZE.
MOVE TABLE-SIZE TO JUMP-SIZE.
PERFORM 1100-SORT-1 UNTIL (SWAP = 'Y') AND (JUMP-SIZE < 2).
1100-SORT-1 SECTION.
COMPUTE JUMP-SIZE = (10 * JUMP-SIZE + 3) / 13.
COMPUTE UPPER-LIMIT = TABLE-SIZE - JUMP-SIZE.
MOVE 'Y' TO SWAP.
PERFORM 2000-SORT-2 VARYING I FROM 1 BY 1
UNTIL I > UPPER-LIMIT.
2000-SORT-2 SECTION.
SET SWAP-NUMBER TO I.
SET SWAP-NUMBER UP BY JUMP-SIZE.
IF SORT-TABLE (I) > SORT-TABLE (SWAP-NUMBER)
MOVE SORT-TABLE (I) TO SWAP-VALUE
MOVE SORT-TABLE (SWAP-NUMBER) TO SORT-TABLE (I)
MOVE SWAP-VALUE TO SORT-TABLE (SWAP-NUMBER)
MOVE 'N' TO SWAP
END-IF.