网站首页 > 文章中心 > 其它

vb.net冒泡法排序

作者:小编 更新时间:2023-08-16 18:15:58 浏览量:403人看过

vb编程 产生10个50-100(包括50和100)的随机整数,并用"冒泡排序"按从小到大的顺序输出.

Private?Sub?Command1_Click()

Dim?a(1?To?10)?As?Integer

Dim?i?As?Integer,?j?As?Integer

For?i?=?1?To?10

Randomize

Print?a(i);

Next?i

Print

Print?"用"冒泡排序"按从小到大的顺序排序后"

For?j?=?1?To?10?-?i

If?a(j)?a(j?◆?1)?Then

t?=?a(j)

a(j)?=?a(j?◆?1)

a(j?◆?1)?=?t

End?If

Next?j

End?Sub

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.

Console.WriteLine("After sorting a section of the Array using the default comparer:")

' Sorts a section of the Array using the reverse case-insensitive comparer.

Console.WriteLine("After sorting a section of the Array using the reverse case-insensitive comparer:")

' Sorts the entire Array using the default comparer.

Array.Sort(myArr)

Console.WriteLine("After sorting the entire Array using the default comparer:")

' 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:")

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

'After sorting a section of the Array using the default comparer:

' [1] : BROWN

'After sorting a section of the Array using the reverse case-insensitive comparer:

'After sorting the entire Array using the default comparer:

' [0] : BROWN

' [1] : dog

'After sorting the entire Array using the reverse case-insensitive comparer:

' [0] : the

' [1] : The

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

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

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

dim flag as Boolean,temp as Integer

flag = true

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

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

For?i?=?LBound(moto)?To?UBound(moto)

Print?moto(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

If k = 10 Then k = 0: Print

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

For i = 1 To 100 '输出排好序的数组

End Sub

VB.NET中的"冒泡排序"问题

N = A(L)

A(L),= A(L ◆1)

(L ◆1) =

结束如果下一页l

此时此刻呢,我

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

以上就是土嘎嘎小编为大家整理的vb.net冒泡法排序相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章