VB冒泡排序程序代码
?const n=10
dim a(1 to 10) as integer,ok as boolean
dim i%,j%,k%
for i=1 to 10
a(i)=int(90*rnd+10) next i
print "得到是十个随机数是:"
for i=1 to 10
print a(i);
next i
print
for i=n to 2 step -1
ok=true
for j=1 to i-1
if a(j)>a(j+1) then
k=a(j)
a(j)=a(j+1)
a(j+1)=k
ok=false
end if
next j
if ok then exit for
next i
print "冒泡排序后的结果为:"
for i=1 to 10
print a(i);
next
print
?Dim a, ok As Boolean, i%, j%, k%
a = Array(5, 7, 4, 3, 8, 6) Print "排序前是:"
For i = LBound(a) To UBound(a)
Print a(i);
Next i
Print
For i = UBound(a) To 2 Step -1
ok = True
For j = LBound(a) To i - 1
If a(j) > a(j + 1) Then
k = a(j)
a(j) = a(j + 1)
a(j + 1) = k
ok = False
End If
Next j
If ok Then Exit For Next i
Print "冒泡排序后的结果为:"
For i = LBound(a) To UBound(a)
Print a(i);
Next
Print