Quick Sort Program In Cobol

Quick Sort Program In Cobol Rating: 5,8/10 1728reviews
Simple Quick Sort Program In CQuick Sort Program In Cobol

Note: Larger/Darker text within each node indicates a higher relevance of the materials to the taxonomic classification. Download Game Guitar Hero Untuk Pc Windows 7.

Bubble sort is a very simple algorithm which compares two neighbouring elements and swaps them if they are not in the right order. In a worst case scenario when the list is already sorted in reverse order, bubble sort will make n^2 comparisons. QuickSort is slighly more complex algorithm that devides the array into two parts using a pivot point and recursively sorts sub arrays. Both BS & QS can be implemented as in-place-sort without needing temp memory space, so they are comparable in terms of memory requirements. So in the end key difference is performance Avg & Worst case performance of bubble sort O(n^2) Best case performance of bubble sort is O(n) - when the list is already sorted. Performance of quick sort is O(n log(n)).

WORKING-STORAGE SECTION. * 01 WS-SORT-AREA. 05 WS-SORT-TABLE. 10 WS-SORT-ROW PIC X(a) OCCURS b. 05 WS-TEMP-ROW PIC X(a). 05 WS-ROW-MAX PIC S9(4) COMP VALUE b. 05 WS-SORT-MAX PIC S9(4) COMP.

05 WS-SORT-UP PIC S9(4) COMP. 05 WS-SORT-DOWN PIC S9(4) COMP. 05 WS-SORT-INCR PIC S9(4) COMP.

05 WS-SORT-TEST PIC S9(4) COMP. * PROCEDURE DIVISION. * MY-SORT SECTION. * * find the last entry * PERFORM VARYING WS-SORT-MAX FROM WS-ROW-MAX BY -1 UNTIL WS-SORT-MAX = ZERO OR WS-SORT-ROW (WS-SORT-MAX) NOT = SPACES END-PERFORM. * * bubble sort into required sequence * PERFORM VARYING WS-SORT-UP FROM WS-SORT-MAX BY -1 UNTIL WS-SORT-UP = ZERO * MOVE ZERO TO WS-SORT-TEST * PERFORM VARYING WS-SORT-DOWN FROM 1 BY 1 UNTIL WS-SORT-DOWN = WS-SORT-UP * ADD 1 TO WS-SORT-DOWN GIVING WS-SORT-INCR * IF WS-SORT-ROW (W30-SORT-DOWN) >WS-SORT-ROW (W30-SORT-INCR) * MOVE WS-SORT-ROW (WS-SORT-DOWN) TO WS-TEMP-ROW MOVE WS-SORT-ROW (WS-SORT-INCR) TO WS-SORT-ROW (WS-SORT-DOWN) MOVE WS-TEMP-ROW TO WS-SORT-ROW (WS-SORT-INCR) ADD 1 TO WS-SORT-TEST END-IF END-PERFORM * IF WS-SORT-TEST = ZERO NEXT SENTENCE END-IF END-PERFORM.

* MY-SORT-EXIT. WORKING-STORAGE SECTION. * 01 WS-SORT-AREA. 05 WS-SORT-TABLE.

10 WS-SORT-ROW PIC X(a) OCCURS b. 05 WS-TEMP-ROW PIC X(a). 05 WS-ROW-MAX PIC S9(4) COMP VALUE b. 05 WS-SORT-MAX PIC S9(4) COMP.

05 WS-SORT-UP PIC S9(4) COMP. 05 WS-SORT-DOWN PIC S9(4) COMP.

05 WS-SORT-INCR PIC S9(4) COMP. 05 WS-SORT-TEST PIC S9(4) COMP. * PROCEDURE DIVISION. * MY-SORT SECTION. * * find the last entry * PERFORM VARYING WS-SORT-MAX FROM WS-ROW-MAX BY -1 UNTIL WS-SORT-MAX = ZERO OR WS-SORT-ROW (WS-SORT-MAX) NOT = SPACES END-PERFORM.

* * bubble sort into required sequence * PERFORM VARYING WS-SORT-UP FROM WS-SORT-MAX BY -1 UNTIL WS-SORT-UP = ZERO * MOVE ZERO TO WS-SORT-TEST * PERFORM VARYING WS-SORT-DOWN FROM 1 BY 1 UNTIL WS-SORT-DOWN = WS-SORT-UP * ADD 1 TO WS-SORT-DOWN GIVING WS-SORT-INCR * IF WS-SORT-ROW (W30-SORT-DOWN) >WS-SORT-ROW (W30-SORT-INCR) * MOVE WS-SORT-ROW (WS-SORT-DOWN) TO WS-TEMP-ROW MOVE WS-SORT-ROW (WS-SORT-INCR) TO WS-SORT-ROW (WS-SORT-DOWN) MOVE WS-TEMP-ROW TO WS-SORT-ROW (WS-SORT-INCR) ADD 1 TO WS-SORT-TEST END-IF END-PERFORM * IF WS-SORT-TEST = ZERO NEXT SENTENCE END-IF END-PERFORM. * MY-SORT-EXIT.

Please enter an answer. Send me notifications when members answer or reply to this question. Early Patch Stage Mycosis Fungoides.