Pseudocode for Bubble Sort:
 
PROCESS
   Initialize FLIP-CT at something other than 0 so SORTPASS 
        will be entered
   Initialize ENDPT to the last element in the array
   DO SORTPASS UNTIL ENDPT < 2 OR FLIPCT = 0
   Show results of sort
   
END PROCESS
SORTPASS
   SUB1 = 1
   SUB2 = 2
   FLIPCT = 0
   DO SORTLOOP UNTIL SUB2 > ENDPT
   SUBTRACT 1 FROM ENDPT
END SORTPASS
SORTLOOP 
   IF ELEM(SUB1) > ELEM(sub2)
      HOLDSLOT = ELEM(SUB1)
      ELEM(SUB1) = ELEM(SUB2)
      ELEM(SUB2) = HOLDSLOT
      FLIPCT = FLIPCT + 1
   ENDIF
   SUB1 = SUB1 + 1
   SUB2 = SUB2 + 1  
END SORTLOOP   
 
Bubble Sort written in COBOL:       
 
       IDENTIFICATION DIVISION.
       PROGRAM-ID.  BUBBLE.
       AUTHOR. GROCER.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  TABLE-IN PIC 9(5) VALUE 56234.
       01  RDF-TABLE-IN REDEFINES TABLE-IN.
           05  TAB-SLOT PIC 9 OCCURS 5 TIMES.
       01  SUB1      PIC 9  VALUE 0.
       01  SUB2      PIC 9  VALUE 0.
       01  END-PT    PIC 9  VALUE 5.
       01  FLIP-CT   PIC 9  VALUE 9.
       01  HOLD-SLOT PIC 9  VALUE 0.
       01  RESPOND   PIC X  VALUE SPACES.
       PROCEDURE DIVISION.
       MAINLINE.
           PERFORM B-100-PROCESS.
           STOP RUN.
       B-100-PROCESS.
           PERFORM B-200-SORT
               UNTIL END-PT = 1 OR FLIP-CT = 0.
           DISPLAY TABLE-IN.
           ACCEPT RESPOND.
       B-200-SORT.
           MOVE 1 TO SUB1.
           MOVE 2 TO SUB2.
           MOVE 0 TO FLIP-CT
           PERFORM B-300-PASS
               UNTIL SUB2 > END-PT.
           SUBTRACT 1 FROM END-PT.
       B-300-PASS.
           IF TAB-SLOT (SUB1) > TAB-SLOT (SUB2)
               MOVE TAB-SLOT (SUB1) TO HOLD-SLOT
               MOVE TAB-SLOT (SUB2) TO TAB-SLOT (SUB1)
               MOVE HOLD-SLOT TO TAB-SLOT (SUB2)
               ADD 1 TO FLIP-CT.
           ADD 1 TO SUB1.
           ADD 1 TO SUB2.

 

 

Bubble Sort in COBOL with embedded pass in code:

 

       IDENTIFICATION DIVISION.
       PROGRAM-ID.  BUBBLE.
       AUTHOR. GROCER.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  TABLE-IN PIC 9(5) VALUE 56234.
       01  RDF-TABLE-IN REDEFINES TABLE-IN.
           05  TAB-SLOT PIC 9 OCCURS 5 TIMES.
       01  SUB1      PIC 9  VALUE 0.
       01  SUB2      PIC 9  VALUE 0.
       01  END-PT    PIC 9  VALUE 5.
       01  FLIP-CT   PIC 9  VALUE 9.
       01  HOLD-SLOT PIC 9  VALUE 0.
       01  RESPOND   PIC X  VALUE SPACES.
       PROCEDURE DIVISION.
       MAINLINE.
           PERFORM B-100-PROCESS.
           STOP RUN.
       B-100-PROCESS.
           PERFORM UNTIL END-PT = 1 OR FLIP-CT = 0
               MOVE 1 TO SUB1
               MOVE 2 TO SUB2
               MOVE 0 TO FLIP-CT
               PERFORM UNTIL SUB2 > END-PT
                   IF TAB-SLOT (SUB1) > TAB-SLOT (SUB2)
                       MOVE TAB-SLOT (SUB1) TO HOLD-SLOT
                       MOVE TAB-SLOT (SUB2) TO TAB-SLOT (SUB1)
                       MOVE HOLD-SLOT TO TAB-SLOT (SUB2)
                       ADD 1 TO FLIP-CT
                   END-IF
                   ADD 1 TO SUB1
                   ADD 1 TO SUB2
               END-PERFORM
               SUBTRACT 1 FROM END-PT
           END-PERFORM
           DISPLAY TABLE-IN.
           ACCEPT RESPOND.

 

Bubble Sort written in Visual Basic:

 

Option Explicit

 

Private Sub cmdClear_Click()

    Dim ct As Integer

    For ct = 0 To 4

        txtNum(ct) = ""

    Next ct

    txtNum(0).SetFocus

End Sub

 

Private Sub cmdExit_Click()

    End

End Sub

 

Private Sub cmdSort_Click()

    Dim endPt As Integer, flipCt As Integer

    Dim sub1 As Integer, sub2 As Integer

    Dim holdSlot As String

    endPt = 4

    flipCt = 9

    Do Until endPt = 0 Or flipCt = 0

       sub1 = 0

       sub2 = 1

       flipCt = 0

       Do Until sub2 > endPt

           If Val(txtNum(sub1)) > Val(txtNum(sub2)) Then

               holdSlot = txtNum(sub1)

               txtNum(sub1) = txtNum(sub2)

               txtNum(sub2) = holdSlot

               flipCt = flipCt + 1

           End If

           sub1 = sub1 + 1

           sub2 = sub2 + 1

      Loop

      endPt = endPt - 1

   Loop

End Sub

 

 

Note that the textboxes on the form are set up as an array.  The first one is txtNum(0) and the next one will be textNum(1) followed by textNum(2), txtNum(3) and txtNum(4).  In doing the sort, I can use these names.