Dim a(1 To 50) As Integer
Dim b(1 To 50) As Integer
Dim c(1 To 50) As Integer
Private Sub Command1_Click()
Dim j As Integer
Me.Text1.Text = "排序前数据" + vbCrLf
j = 1
While j <= 50 '产生随机数
a(j) = Int(100 * Rnd())
Me.Text1.Text = Me.Text1.Text + Mid(CStr(a(j)) + " ", 1, 4)
If j Mod 10 = 0 Then '满10个就要换行
Me.Text1.Text = Me.Text1.Text + vbCrLf
End If
j = j + 1
Wend '产生随机数 完毕
For j = 1 To 50
b(j) = a(j)
c(j) = a(j)
Next
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer, k As Integer
For i = 1 To 49
For j = 1 To 49
If b(j) > b(j + 1) Then
k = b(j): b(j) = b(j + 1): b(j + 1) = k
End If
Next
Next
Me.Text1.Text = Me.Text1.Text + "冒泡排序后数据" + vbCrLf
For i = 1 To 50
Me.Text1.Text = Me.Text1.Text + Mid(CStr(b(i)) + " ", 1, 4)
If i Mod 10 = 0 Then
Me.Text1.Text = Me.Text1.Text + vbCrLf
End If
Next
End Sub
Private Sub Command3_Click()
Dim i As Integer, j As Integer, k As Integer
For i = 1 To 50
For j = i To 50
If c(i) < c(j) Then
k = c(i): c(i) = c(j): c(j) = k
End If
Next
Next
Me.Text1.Text = Me.Text1.Text + "选择排序后数据" + vbCrLf
For i = 1 To 50
Me.Text1.Text = Me.Text1.Text + Mid(CStr(c(i)) + " ", 1, 4)
If i Mod 10 = 0 Then
Me.Text1.Text = Me.Text1.Text + vbCrLf
End If
Next
End Sub
温馨提示:答案为网友推荐,仅供参考