Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Rearrange the following VBA program in the correct order based on the following

ID: 667446 • Letter: R

Question

Rearrange the following VBA program in the correct order based on the following flowchart of bubble sort.

2

switch = False
For i = 1 To m

1

Option Explicit

Sub Bubble(n, b)
Dim m As Integer, i As Integer
Dim switch As Boolean, dum As Double
m = n - 1

5

Next i
    If switch = False Then Exit Do
    m = m - 1
Loop
End Sub

If b(i) > b(i + 1) Then
   dum = b(i)
   b(i) = b(i + 1)
   b(i + 1) = dum
   switch = true
End If

Do

start m=n- switch = false i=1 im i=i+1 TNot switch ai> ai41 swap aa-1 m=m-1 switch = true end

Explanation / Answer

Option Explicit

Sub bubble(n, b)
Dim m As Integer, i As Integer
Dim switch As Boolean, dum As Double

m = n - 1
Do
switch = False
For i = 1 To m
If b(i) > b(i + 1) Then
dum = b(i)
b(i) = b(i + 1)
b(i + 1) = dum
switch = True
End If
Next i
If switch = False Then Exit Do
m = m - 1
Loop
End Sub