srkp.net
当前位置:首页 >> vB,我知道是冒泡排序法,可是,F=truE 和F=FAlsE... >>

vB,我知道是冒泡排序法,可是,F=truE 和F=FAlsE...

不一定要那么多排序才能把那个数组排好 如果说,其中一次循环,没有发生一次排序,那证明数组已经排好了 那f还是为true,就可以直接退出循环,不用浪费资源了

f = True 这是将逻辑“真”赋值给f变量,当排序全部完成时,f肯定为真 重要是: If f Then Exit For End If 当f为真时,退出外循环,表示结束

For i = 1 To 10 For j = 1 To 10 - i If a(j) > a(j + 1) Then temp = a(j + 1) a(j + 1) = a(j) a(j) = temp End If Next j Next i

随即产生10个0~100的数,并按从小到大排序 Private Sub Command1_Click() Dim num(1 To 10) As Integer Dim i, j, t As Integer For i = 1 To 10 num(i) = Int((100 - 0 + 1) * Rnd + 0) Next For i = 1 To 10 For j = i + 1 To 10 If num(i) > n...

就是比较数值,把大的或小的放在前面 比如,有一个数组a()包含{5,7,3,9,12,15,56}7个数 dim t as integer for i=0 to a.count-1 for j=i+1 to a.count-1 t=a(i) if a(i) a(i + 1)) Then '若是递减,改为a(i)

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.C...

冒泡排序,在每一次比较的时候,如果发现相邻两数的次序不对,都会马上就把两数进行对调。 选择排序,则在比较过程中(内循环里面)并不进行对调,而是先记录下最小(大)数的下标,在一次扫描完成后再进行对调。所以它的效率会比冒泡的高一点。...

Dim a%(8) Private Sub command1_click() Dim s$ For i = 1 To 8 a(i) = Int(Rnd * 90 + 10) s = s + Str(a(i)) Next Text1 = s End Sub Private Sub command2_click() Dim s$ For i = 1 To 7 For j = 1 To 8 - i If a(j) < a(j + 1) Then t = a...

Option Base 1 Private Sub Command1_Click() Dim a Dim b As Integer Dim i As Integer Dim j As Integer a = Array(6, 3, 7, 8, 2, 1) Print "排序前为"; For i = 1 To 6 Print a(i); Next i For i = 1 To 5 For j = 1 To 6 - i If a(j) > a(j...

如果五个号码为数组元素(1)到(5),正确的排序过程: 对于i = 1至4 对于L = 1到5 - 如果A(L)(L +1) N = A(L) A(L),= A(L +1) (L +1) = 结束如果下一页l 接下来,我 能够到第一台计算机来验证结果,然后分析程序。

网站首页 | 网站地图
All rights reserved Powered by www.srkp.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com