Public Class Form1
Dim i, j
Dim str1 = ""
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'原資料
Dim a() = {5, 4, 3, 2, 1}
'排序前資料記錄
str1 = "原資料" & vbNewLine
str1 = str1 & a(0) & a(1) & a(2) & a(3) & a(4) & vbNewLine
str1 = str1 & "-- 過程 -- " & vbNewLine
'排序
For j = 0 To 3
For i = 0 To 3
If a(i) > a(i + 1) Then
Dim t = a(i)
a(i) = a(i + 1)
a(i + 1) = t
End If
Next i
'排序過程資料記錄
str1 = str1 & a(0) & a(1) & a(2) & a(3) & a(4) & vbNewLine
Next j
'最後結果輸出
MsgBox(str1)
End Sub
End Class
沒有留言:
張貼留言