Public Class Form1
Dim arr(5) As Integer
Dim a(5, 5) As TextBox
Private Sub delaytime()
Dim i, j As Long
For i = 1 To 20000
For j = 1 To 20000
i = i + 1
i = i - 1
Next j
Next i
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "数ºy组Á¨¦元a素?值¦Ì:êo"
Label2.Text = "第̨²一°?轮?:êo"
Label3.Text = "第̨²二t轮?:êo"
Label4.Text = "第̨²三¨y轮?:êo"
Label5.Text = "第̨²四?轮?:êo"
Label6.Text = "第̨²五?轮?:êo"
Button1.Text = "产¨²生¦¨²数ºy组Á¨¦"
Button2.Text = "选?择?法¤¡§演Y示º?"
Button3.Text = "冒¡ã泡Y法¤¡§演Y示º?"
Button4.Text = "重?新?开a始º?"
Button5.Text = "退ª?出?"
Dim i, j As Integer
Dim leftlen, toplen As Integer
leftlen = 120 : toplen = 32
Randomize()
For i = 0 To 5
For j = 0 To 5
a(i, j) = New TextBox
a(i, j).Width = 30 : a(i, j).Height = 30
a(i, j).Left = leftlen + j * 40 : a(i, j).Top = toplen + i * 32
a(i, j).Parent = Me : a(i, j).Visible = True
Next j
Next i
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, j As Integer
For i = 0 To 5
arr(i) = Int(10 + 89 * Rnd()) + 1
a(0, i).Text = arr(i)
Next i
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i, j As Integer
Dim min, min_i As Integer
Dim t As Integer
For i = 0 To 5 - 1
min = arr(i) : min_i = i
For j = i + 1 To 5
If min > arr(j) Then
min = arr(j) : min_i = j
End If
Next j
a(i, min_i).BackColor = System.Drawing.Color.Yellow
a(i, i).BackColor = System.Drawing.Color.LightCyan
Me.Refresh()
If min_i <> i Then
t = arr(min_i) : arr(min_i) = arr(i) : arr(i) = t
End If
For j = 0 To 5
a(i + 1, j).Text = arr(j)
Next j
Call delaytime()
Me.Refresh()
Next i
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim i, j, k, t As Integer
For i = 1 To 5
For k = 0 To 5
a(i, k).Text = arr(k)
Next k
Me.Refresh()
Call delaytime()
For j = 0 To 5 - i
a(i, j).BackColor = System.Drawing.Color.LightCyan
a(i, j + 1).BackColor = System.Drawing.Color.LightC yan
Me.Refresh()
Call delaytime()
If arr(j) > arr(j + 1) Then
t = arr(j) : arr(j) = arr(j + 1) : arr(j + 1) = t
a(i, j).Text = arr(j) : a(i, j + 1).Text = arr(j + 1)
End If
Me.Refresh()
Call delaytime()
a(i, j).BackColor = System.Drawing.Color.WhiteSmoke
a(i, j + 1).BackColor = System.Drawing.Color.WhiteSmoke
Next j
Next i
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim i, j As Integer
For i = 0 To 5
For j = 0 To 5
a(i, j).Text = ""
a(i, j).BackColor = System.Drawing.Color.WhiteSmoke
Next j
Next i
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
End
End Sub
End Class。