Answer
Subroutine BubbleFor(n, b)
Implicit None
!sorts an array in ascending
!order using the bubble sort
Integer(4)::m, i, n
Logical::switch
Real::a(n),b(n),dum
m=n-1
Do
switch = .False.
Do i = 1, m
If (b(i) > b(i + 1)) Then
dum = b(i)
b(i) = b(i + 1)
b(i + 1) = dum
switch = .True.
End If
End Do
If (switch == .False.) Exit m=m-1
End Do End
2.14 Here is a flowchart for the algorithm:
d 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
Work Step by Step
Subroutine BubbleFor(n, b)
Implicit None
!sorts an array in ascending
!order using the bubble sort
Integer(4)::m, i, n
Logical::switch
Real::a(n),b(n),dum
m=n-1
Do
switch = .False.
Do i = 1, m
If (b(i) > b(i + 1)) Then
dum = b(i)
b(i) = b(i + 1)
b(i + 1) = dum
switch = .True.
End If
End Do
If (switch == .False.) Exit m=m-1
End Do End
2.14 Here is a flowchart for the algorithm:
d 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