Private Sub Command1_Click()
Dim a(1 To 10) As Integer
For i = 1 To 10
a(i) = Int(Rnd * 10)
Print a(i)
Next i
'以上十随机得出10个数
For i = 1 To 9 '这里开始是双重循环
For j = i + 1 To 10
If a(i) >a(j) Then '如果前一个数大于后一个数则交换位置
t = a(i): a(i) = a(j): a(j) = t
End If
Next j
Print a(i)
Next i
Print a(i)End Sub
I等于1时 就是拿第一位和第二位比较 比较大的的数排后面 然后比较第一位和第谈备三位 For j = i + 1
To 10 直到比较到最后一位
i=2 时也是如此 循环9次就完成排序5 3 2 7
i=1 时
J=2时 3 5 2 7
J=3时 2 5 3 7
j=4时 2 5 3 7
I=2时含亏毁
j=3时 2 3 5 7扩展资料
Private Sub 空基Command1_Click()
Dim a(10) As Integer
Dim b As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
For i = 1 To 10
a(i) = Int(Rnd * 90 + 10)
Print a(i)
Next i
PrintFor i = 1 To 9
k = i
For j = k + 1 To 10
If a(j) < a(k) Then k = j
Next j
If a(i) > a(k) Then
b = a(i)
a(i) = a(k)
a(k) = bEnd If
Next iFor i = 1 To 10
Print a(i)Next i
参考资料:百度百科 - 选择法排序
for i=1 to n-1for j=i+1 to n
if a(i)>正羡租a(j) then
tmp=a(i)
a(i)=a(j)
a(j)=tmp
next
next
冒泡排派袭序举兆法
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)