Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDENTIFICATION DIVISION.
- PROGRAM-ID. ORDENAMIENTO-POR-SELECCION.
- DATA DIVISION.
- WORKING-STORAGE SECTION.
- 01 TIMESTAMP.
- 02 FILLER PIC 9(06).
- 02 MS PIC 9(02).
- 77 TABLA PIC 9(02) OCCURS 20 INDEXED BY I.
- 77 AUX PIC 9(02).
- 77 J PIC 9(02).
- PROCEDURE DIVISION.
- MAIN-PROCEDURE.
- PERFORM RELLENAR-TABLA.
- DISPLAY "TABLA ORIGINAL".
- PERFORM MOSTRAR-TABLA.
- PERFORM ORDENAR-TABLA.
- DISPLAY "TABLA ORDENADA".
- PERFORM MOSTRAR-TABLA.
- STOP RUN.
- MOSTRAR-TABLA.
- PERFORM VARYING I FROM 1 BY 1 UNTIL I > 19
- DISPLAY TABLA(I), ", " WITH NO ADVANCING
- END-PERFORM.
- DISPLAY TABLA(I).
- RELLENAR-TABLA.
- COMPUTE TABLA(1) = FUNCTION RANDOM(FUNCTION SECONDS-PAST-MIDNIGHT) * 99 + 1.
- PERFORM VARYING I FROM 2 BY 1 UNTIL I > 20
- COMPUTE TABLA(I) = FUNCTION RANDOM * 99 + 1
- END-PERFORM.
- ORDENAR-TABLA.
- PERFORM VARYING I FROM 1 BY 1 UNTIL I > 20
- MOVE I TO AUX
- PERFORM VARYING J FROM I BY 1 UNTIL J > 20
- IF TABLA(AUX) > TABLA(J) THEN
- MOVE J TO AUX
- END-IF
- END-PERFORM
- *> REUTILIZACION DE AUX. AQUÍ SE PUEDE. EN OTRO CONTEXTO TAL VEZ SERIA
- *> NECESARIA UNA VARIABLE AUXILIAR
- MOVE AUX TO J
- MOVE TABLA(I) TO AUX
- MOVE TABLA(J) TO TABLA(I)
- MOVE AUX TO TABLA(J)
- END-PERFORM.
- END PROGRAM ORDENAMIENTO-POR-SELECCION.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement