大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
1、点击VS工具。
创新互联-专业网站定制、快速模板网站建设、高性价比康马网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式康马网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖康马地区。费用合理售后完善,10年实体公司更值得信赖。
2、打开后,新建一个Windows窗体应用程序。
3、新建完毕后,如图所示。
4、拖动一个按钮。
5、定义数组最常见的方法,如图示。
6、运行后,点击按钮,弹出提示正常。
7、定义数组第二种方法,属于动态的方法。
8、运行后,点击按钮,数组成功输出。
呵呵。
这个不难理解啊,冒泡法就是先取最大的然后依次往下,排完后就是从大到小,比如1,2,3,4,5
外层就是从第一位到第五位,比较第一位。从头到尾的选
5最大,放到第一位,就变成5,1,2,3,4,下一轮,因为5已经选
出来了,第一位就不用比了。只有1.2.3.4,这下就只有四位了,次数就是n-i了。到了第几位只跟他后面的几位比,前面的不管,所以。。不知道你明白没
外层就是从1-5,每位操作一次,内层就是从外层选定的位置开始,向后比较。
For
i
=
1
To
50
For
j
=
i
To
50
If
aa(i)
aa(j)
Then
kk
=
aa(i)
aa(i)
=
aa(j)
aa(j)
=
kk
End
If
Next
Next
随即产生10个0~100的数,并按从小到大排序,已经验证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爱好者,以后互相学习,互相努力哦!!!^_^
试试看:
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
如果你是从vb6刚过渡上vb。net,建议还是用冒泡排序法,容易理解。
如果你正努力学习vb。net的方法,推荐一个例子如下:
Imports System
Imports System.Collections
Public Class SamplesArray
Public Class myReverserClass
Implements IComparer
' Calls CaseInsensitiveComparer.Compare with the parameters reversed.
Function Compare(x As Object, y As Object) As Integer _
Implements IComparer.Compare
Return New CaseInsensitiveComparer().Compare(y, x)
End Function 'IComparer.Compare
End Class 'myReverserClass
Public Shared Sub Main()
' Creates and initializes a new Array and a new custom comparer.
Dim myArr As [String]() = {"The", "QUICK", "BROWN", "FOX", "jumps", "over", "the", "lazy", "dog"}
Dim myComparer = New myReverserClass()
' Displays the values of the Array.
Console.WriteLine("The Array initially contains the following values:")
PrintIndexAndValues(myArr)
' Sorts a section of the Array using the default comparer.
Array.Sort(myArr, 1, 3)
Console.WriteLine("After sorting a section of the Array using the default comparer:")
PrintIndexAndValues(myArr)
' Sorts a section of the Array using the reverse case-insensitive comparer.
Array.Sort(myArr, 1, 3, myComparer)
Console.WriteLine("After sorting a section of the Array using the reverse case-insensitive comparer:")
PrintIndexAndValues(myArr)
' Sorts the entire Array using the default comparer.
Array.Sort(myArr)
Console.WriteLine("After sorting the entire Array using the default comparer:")
PrintIndexAndValues(myArr)
' Sorts the entire Array using the reverse case-insensitive comparer.
Array.Sort(myArr, myComparer)
Console.WriteLine("After sorting the entire Array using the reverse case-insensitive comparer:")
PrintIndexAndValues(myArr)
End Sub 'Main
Public Shared Sub PrintIndexAndValues(myArr() As [String])
Dim i As Integer
For i = 0 To myArr.Length - 1
Console.WriteLine(" [{0}] : {1}", i, myArr(i))
Next i
Console.WriteLine()
End Sub 'PrintIndexAndValues
End Class 'SamplesArray
'This code produces the following output.
'
'The Array initially contains the following values:
' [0] : The
' [1] : QUICK
' [2] : BROWN
' [3] : FOX
' [4] : jumps
' [5] : over
' [6] : the
' [7] : lazy
' [8] : dog
'
'After sorting a section of the Array using the default comparer:
' [0] : The
' [1] : BROWN
' [2] : FOX
' [3] : QUICK
' [4] : jumps
' [5] : over
' [6] : the
' [7] : lazy
' [8] : dog
'
'After sorting a section of the Array using the reverse case-insensitive comparer:
' [0] : The
' [1] : QUICK
' [2] : FOX
' [3] : BROWN
' [4] : jumps
' [5] : over
' [6] : the
' [7] : lazy
' [8] : dog
'
'After sorting the entire Array using the default comparer:
' [0] : BROWN
' [1] : dog
' [2] : FOX
' [3] : jumps
' [4] : lazy
' [5] : over
' [6] : QUICK
' [7] : the
' [8] : The
'
'After sorting the entire Array using the reverse case-insensitive comparer:
' [0] : the
' [1] : The
' [2] : QUICK
' [3] : over
' [4] : lazy
' [5] : jumps
' [6] : FOX
' [7] : dog
' [8] : BROWN