单击窗体,分别在窗体上输出这10个数的正逆排序
请各位说说自己的思路,让小弟也好学习一下
谢谢了……………………
Option Explicit
Private Sub Command1_Click()
Randomize
Dim i As Integer, j As Integer
Dim a(1 To 10) As Integer
Dim temp As Integer
For i = 1 To 10
a(i) = Int(90 * Rnd) '产生随机数,赋给数组a
Next
Print "排序前"
For i = 1 To 10
Print a(i);
Next
Print
'使用冒泡排序法
For i = 1 To 10
For j = 1 To 10 - i
If a(j) > a(j + 1) Then
temp = a(j)
a(j) = a(j + 1)
a(j + 1) = temp
End If
Next
Next
Print "升序:"
For i = 1 To 10
Print a(i);
Next
Print
For i = 1 To 10
For j = 1 To 10 - i
If a(j) < a(j + 1) Then
temp = a(j)
a(j) = a(j + 1)
a(j + 1) = temp
End If
Next
Next
Print "降序"
For i = 1 To 10
Print a(i);
Next
Print
End Sub