vb.net冒泡法 vb中怎么用冒泡法排序
VB.NET中的“冒泡排序”问题
如果五个号码为数组元素(1)到(5),正确的排序过程:
创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都做网站、成都网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的扎兰屯网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
对于i = 1至4
对于L = 1到5 - 如果A(L)(L +1)
N = A(L)
A(L),= A(L +1)
(L +1) =
结束如果下一页l
接下来,我
能够到第一台计算机来验证结果,然后分析程序。
使用vb.net编写一个函数,函数只有一个参数
首先在窗体上添加Button1,ListBox1,下面是完整代码
Public Class Form1
Public Sub BubbleSort(ByVal arr() As Integer) '冒泡法排序
Dim temp As Double
Dim i, j As Integer
For i = 0 To arr.GetUpperBound(0) - 1
For j = i + 1 To arr.GetUpperBound(0) - 1
If arr(i) arr(j) Then
temp = arr(j)
arr(j) = arr(i)
arr(i) = temp
End If
Next
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '调用
Dim arr() As Integer = {55, 22, 33, 11, 77, 88}
BubbleSort(arr) '调用排序过程
Me.ListBox1.Items.Clear()
For i = 0 To arr.GetUpperBound(0) - 1 '显示排序后结果
Me.ListBox1.Items.Add(arr(i).ToString)
Next
End Sub
End Class
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中X为 4,9,12,15,22,33,44,66,72,84,87,92,96,98,99 Y为6,8,12,16,24,31,68,71,73,74,81,93,94将X
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x, y As String
x = "4,9,12,15,22,33,44,66,72,84,87,92,96,98,99"
y = "6,8,12,16,24,31,68,71,73,74,81,93,94"
Dim g() As Integer
g = Array.ConvertAll((x "," y).Split(","), New Converter(Of String, Integer)(AddressOf strToint))
System.Array.Sort(g)
Dim g_str() As String
g_str = Array.ConvertAll(g, New Converter(Of Integer, String)(AddressOf IntTostr))
Dim My_text As String = Join(g_str, ",")
My_text = Regex.Replace(My_text, "\b(\w+),(?=\1)\b", "") 'My_text是最终结果
End Sub
Public Shared Function strToint(ByVal bs As String)
Return CInt(bs)
End Function
Public Shared Function IntTostr(ByVal bs As Integer)
Return CStr(bs)
End Function
End Class
My_text是最终结果,重复的12被自动剔除了
当前题目:vb.net冒泡法 vb中怎么用冒泡法排序
文章链接:http://ybzwz.com/article/dodigii.html