2019年5月28日 星期二
陣列排序
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a(5) As Integer
Dim n, temp As Integer
n = 1
For i = 1 To 5
a(i) = Mid(TextBox1.Text, n, 2)
n = n + 3
Next
Label2.Text = "5個陣列元素以選擇排序法排序,共需4次循環" & vbCrLf
For x = 4 To 1 Step -1
Label2.Text = Label2.Text & "第" & 5 - x & "循環結果為"
For y = 1 To x
If a(y) > a(y + 1) Then
temp = a(y)
a(y) = a(y + 1)
a(y + 1) = temp
End If
Next
For i = 1 To 5
Label2.Text = Label2.Text & a(i) & " "
Next
Label2.Text = Label2.Text & vbCrLf
Next
End Sub
End Class
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言