vb程序设计中插入排序
发布网友
发布时间:2022-05-12 02:37
我来回答
共1个回答
热心网友
时间:2023-11-04 09:19
Private Sub form_click()
Randomize
Dim tmp As Integer
Dim a(1 To 10) As Integer
'开始随机生成10个数
For i = 1 To 10
a(i) = Int(Rnd * 99)
Next i
'开始插入排序
For i = 2 To 10
If a(i) > a(i - 1) Then
tmp = a(i)
For j = i - 1 To 1 Step -1
If tmp < a(j) Then Exit For
a(j + 1) = a(j)
Next j
a(j + 1) = tmp
End If
Next i
Print "排序结果:"
For i = 1 To 10
Print a(i);
Next i
Print
End Sub