
vb中的冒泡排序法,怎么通过界面实时动态显示排序过程
展开全部
Dim a(8) As Integer
Dim cou As Integer
Dim temp As Integer
Sub shownum()
Command1.Caption = a(1)
Command2.Caption = a(2)
Command3.Caption = a(3)
Command4.Caption = a(4)
Command5.Caption = a(5)
Command6.Caption = a(6)
Command7.Caption = a(7)
Command8.Caption = a(8)
End Sub
Private Sub Command10_Click()
cou = 0
For i = 1 To 8
For j = 1 To 8 - i
cou = cou + 1
If a(j) > a(j + 1) Then
temp = a(j + 1)
a(j + 1) = a(j)
a(j) = temp
End If
Call shownum
MsgBox ("完成第" & cou & "次排序")
Next j
Next i
MsgBox ("完成所有排序,共进行" & cou & "次排序")
End Sub
Private Sub Command9_Click()
Randomize
For i = 1 To 8
a(i) = Int(Rnd * 100) + 10
Next i
Call shownum
End Sub
Private Sub Form_Load()
cou = 0
End Sub
Dim cou As Integer
Dim temp As Integer
Sub shownum()
Command1.Caption = a(1)
Command2.Caption = a(2)
Command3.Caption = a(3)
Command4.Caption = a(4)
Command5.Caption = a(5)
Command6.Caption = a(6)
Command7.Caption = a(7)
Command8.Caption = a(8)
End Sub
Private Sub Command10_Click()
cou = 0
For i = 1 To 8
For j = 1 To 8 - i
cou = cou + 1
If a(j) > a(j + 1) Then
temp = a(j + 1)
a(j + 1) = a(j)
a(j) = temp
End If
Call shownum
MsgBox ("完成第" & cou & "次排序")
Next j
Next i
MsgBox ("完成所有排序,共进行" & cou & "次排序")
End Sub
Private Sub Command9_Click()
Randomize
For i = 1 To 8
a(i) = Int(Rnd * 100) + 10
Next i
Call shownum
End Sub
Private Sub Form_Load()
cou = 0
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |