The PL/I Programming Language

Bubble Sort Example Program


Click below to go directly to a specific section:
Description | Source Code | Program Notes

Description

This is an example of what a typical Bubble Sort would look like if it was written in the PL/I programming language.

Source Code

SHELL:   PROCEDURE OPTIONS (MAIN);
         DECLARE
           ARRAY(50) FIXED BIN(15),
           (K,N) FIXED BIN(15);

         GET LIST(N);
         GET EDIT((ARRAY(K) DO K = 1 TO N));
         PUT EDIT((ARRAY(K) DO K = 1 TO N));
         CALL BUBBLE(ARRAY,N);

END BUBBLE;

BUBBLE:   PROCEDURE(ARRAY,N); /* BUBBLE SORT*/
          DECLARE (I,J) FIXED BIN(15);
          DECLARE S BIT(1);        /* SWITCH */
          DECLARE Y FIXED BIN(15); /* TEMPO */
          DO I = N-1 BY -1 TO 1;
            S = '1'B;
            DO J = 1 TO I;
              IF X(J)>X(J+1) THEN DO;
                S = '0'B;
                Y = X(J);
                X(J) = X(J+1);
                X(J+1) = Y;
                END;
              END;
            IF S THEN RETURN;
            END;
          RETURN;
          END SRT;             

Program Notes

This program was not tested due to unavailablility of a compiler.
[Back] [Home]

Last modified: 03:37 PM on 11/09/1996