1、随机产生10个10-99范围内的整数,分别用选择和冒泡法将数据按从大到小递减的顺序排列,并显示排序结果
问题描述:
1、随机产生10个10-99范围内的整数,分别用选择和冒泡法将数据按从大到小递减的顺序排列,并显示排序结果
答
Private Sub Form_click()
Dim A(1 To 10)
Randomize
For I = 1 To 10
A(I) = Int(Rnd * 90) + 10
Next I
For I = 1 To 9 '选择法
p = I
For J = I + 1 To 10
If A(J) p = J
End If
Next J
tem = A(I)
A(I) = A(p)
A(p) = tem
Next I
For I = 1 To 10
A(I) = A(11 - I)
Next I
For I = 1 To 9 '冒泡法
For J = 1 To 10 - I
If A(J) > A(J + 1) Then
tem = A(I)
A(I) = A(p)
A(p) = tem
End If
Next J
Next I
For I = 1 To 10
A(I) = A(11 - I)
Next I
End Sub
这就好了 你试试哦