大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
给你一个最简单的冒泡排序代码:
创新互联公司-专业网站定制、快速模板网站建设、高性价比禹会网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式禹会网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖禹会地区。费用合理售后完善,十余年实体公司更值得信赖。
将三个数放到一个数组中。
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)
Dim d() As Integer
Dim n As Integer
Dim i As Integer
Dim j As Integer
Dim T As Integer
n = Val(InputBox("请输入n,确定数组的元素个数"))
ReDim d(n)
'用随机函数生成正整数数组
Randomize
For i = 1 To n
d(i) = Int(Rnd * 100 + 1)
Next i
'输出
For i = 1 To n
Print d(i),
Next i
'从小到大排序
For i = 1 To n - 1
For j = i + 1 To n
If d(i) d(j) Then
T = d(i)
d(i) = d(j)
d(j) = T
End If
Next j
Next i
'输出
For i = 1 To n
Print d(i),
Next i
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Items.Add("Apple")
ListBox1.Items.Add("Cat")
ListBox1.Items.Add("Yellow")
ListBox1.Items.Add("Guilty")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Sorted = True
End Sub
End Class