vb.net冒泡排序代码 vb冒泡法排序代码

vb冒泡排序看上面那一大段vb.net冒泡排序代码,我晕了(╯﹏╰)b
下面的是从小到大排序的vb.net冒泡排序代码 , 从大到小只需改一个“”号vb.net冒泡排序代码,看下面的注释vb.net冒泡排序代码,整个过程不变的 。
Private Sub Command1_Click()
Dim x(1 To 5) As Double, i%, j%, t
x(1) = Val(Text1)
x(2) = Val(Text2)
x(3) = Val(Text3)
x(4) = Val(Text4)
x(5) = Val(Text5)
For i = 1 To 5 - 1'有5个数要排序vb.net冒泡排序代码,需要进行5-1=4次两两比较
For j = 5 To i + 1 Step -1 '从末尾一个元素到第i个元素进行两两比较
If x(j)x(j - 1) Then'从小到大排序 , 若需要从大到小排序,将“”改为“”
'若次序不对,则马上交换位置
t = x(j)
x(j) = x(j - 1)
x(j - 1) = t
End If
Next j '除了内循环 , 一轮排序结束 , 最?。ɑ蜃畲螅┦丫暗绞榈谝晃?
Next i
Label1.Caption = x(1)
Label2.Caption = x(2)
Label3.Caption = x(3)
Label4.Caption = x(4)
Label5.Caption = x(5)
End Sub
vb冒泡排序代码随即产生10个0~100vb.net冒泡排序代码的数,并按从小到大排序,已经验证OK!!!
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)num(j) Then
t = num(i)
num(i) = num(j)
num(j) = t
End If
Next j
Next i
For i = 1 To 10
Print num(i)
Next
End Sub
vb.net冒泡排序代码我也是VB爱好者,以后互相学习,互相努力哦!!!^_^
vb.net冒泡排序法代码试试看:
For i = LBound(moto) To UBound(moto) - 1
For j = LBound(moto) To UBound(moto) - 1 - i
If moto(j)moto(j + 1) Then
t = moto(j)
moto(j) = moto(j + 1)
moto(j + 1) = t
End If
Next j
Next i
For i = LBound(moto) To UBound(moto)
Print moto(i);
Next i
vb.net的随机3个数字,然后排序一下给vb.net冒泡排序代码你一个最简单vb.net冒泡排序代码的冒泡排序代码vb.net冒泡排序代码:
将三个数放到一个数组中 。
a(0)=val(text1.text):a(1)=val(text2.text):a(2)=val(text3.text)
dim flag as Boolean,temp as Integer
for i = 0 to 2
flag = true
for j = 2 to 1
if a(j)a(j-1) then
temp = a(j-1)
a(j-1) = a(j)
a(j) = temp
flag = false
end if
next j
if flag then Exit For
next i
text4.text=a(0):text5.text=a(1):text6.text=a(2)
编写一个 VB.NET 程序,产生 100 个 100 以内的随机数,将他们从大到小排序后输出Private Sub Command1_Click()
Dim a(1 To 100) As Integer
Dim i As Integer, j As Integer, k As Integer
For i = 1 To 100'给数组a一百个元素赋值vb.net冒泡排序代码,并换每行十个数字输出来窗体上
a(i) = Int(Rnd * 101)
k = k + 1
Print Tab((k - 1) * 5); a(i);
If k = 10 Then k = 0: Print
Next i
Print
Print
For i = 100 To 2 Step -1'用冒泡排序法对数组进行排序
For j = 1 To i - 1
If a(j)a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
For i = 1 To 100'输出排好序vb.net冒泡排序代码的数组
k = k + 1
Print Tab((k - 1) * 5); a(i);
If k = 10 Then k = 0: Print
Next i
End Sub
VB的排序法的代码排序的各类很多,最简单的冒泡排序代码如下:
Private Sub Command1_Click()
Dim a(), i As Integer, j As Integer, tmp As Integer
a = Array(1, 3, 2, 5, 4, 6, 9, 7, 8, 0)
Print Join(a, ",")
For i = 0 To UBound(a)
For j = i + 1 To UBound(a)

推荐阅读