重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Dim i, j As Integer
创新互联专注于潼关企业网站建设,自适应网站建设,商城建设。潼关网站建设公司,为潼关等地区提供建站服务。全流程按需定制,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务
For i = q - 1 To 0 Step -1
For j = 0 To i
If a(j) a(j + 1) Then
w = a(j) : a(j) = a(j + 1) : a(j + 1) = w
End If
Next
Next
冒泡法排序
你这个是冒泡排序么?从大到小么?
For j = 0 To lstNetworkRisk.Items.Count - 1 应该改成
For j = i To lstNetworkRisk.Items.Count - 1
另外尽量不要用GOTO语句。而且完全也可以不用这个GOTO。
还有不知道你用的什么版本的.net 如果是3.5的完全可以直接用linq。
给你一个最简单的冒泡排序代码:
将三个数放到一个数组中。
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)
首先在窗体上添加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