快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

vb.net冒泡排序 net 冒泡排序

VB.NET中的“冒泡排序”问题

如果五个号码为数组元素(1)到(5),正确的排序过程:

成都创新互联公司是一家专注于做网站、成都网站制作与策划设计,迎江网站建设哪家好?成都创新互联公司做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:迎江等地区。迎江做网站价格咨询:028-86922220

对于i = 1至4

对于L = 1到5 - 如果A(L)(L +1)

N = A(L)

A(L),= A(L +1)

(L +1) =

结束如果下一页l

接下来,我

能够到第一台计算机来验证结果,然后分析程序。

(VB.NET)编写完整程序,分别模拟实现顺序查找,二分查找,选择排序,改进的选择排序,冒泡排序,

10分太少了,题目多,而且写了也不一定会采纳,所以没人回答。

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 程序,产生 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一百个元素赋值,并换每行十个数字输出来窗体上

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 '输出排好序的数组

k = k + 1

Print Tab((k - 1) * 5); a(i);

If k = 10 Then k = 0: Print

Next i

End Sub

VB.NET数组的排序法?

如果你是从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

vb.net的随机3个数字,然后排序一下

给你一个最简单的冒泡排序代码:

将三个数放到一个数组中。

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冒泡排序 net 冒泡排序
URL网址:http://6mz.cn/article/dooicpo.html

其他资讯