如果五个号码为数组元素(1)到(5),正确的排序过程:
创新互联公司专业为企业提供广河网站建设、广河做网站、广河网站设计、广河网站制作等企业网站建设、网页设计与制作、广河企业网站模板建站服务,10多年广河做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
对于i = 1至4
对于L = 1到5 - 如果A(L)(L +1)
N = A(L)
A(L),= A(L +1)
(L +1) =
结束如果下一页l
接下来,我
能够到第一台计算机来验证结果,然后分析程序。
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim N As Integer = 9
Randomize()
Dim xx(9) As Integer
For i As Integer = 0 To N
xx(i) = Int(Rnd() * 1000) '产生 [0,1000) 之间的整数
Next
For i As Integer = 0 To N - 1
For j As Integer = i + 1 To N
If xx(i) xx(j) Then
Dim temp As Integer = 0
temp = xx(i) : xx(i) = xx(j) : xx(j) = temp
End If
Next
Next
Dim sum As Integer = 0
For i As Integer = 0 To N
TextBox1.Text += xx(i) vbCrLf
sum += xx(i)
Next
TextBox1.Text += "最大值:" xx(9) vbCrLf "最小值:" xx(0) vbCrLf "平均值:" sum / 10
End Sub
End Class
窗体上添加3个标签,1个按钮,在按钮的单击事件里写代码,如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a(,) As Integer = {{5, 6}, {1, 3}, {8, 9}, {72, 1}, {63, 4}}
Dim Temp As Integer
Dim i As Integer
Dim j As Integer
Dim x As Integer
Dim y As Integer
'显示排序前的数据
Label1.Text = "排序前数据:" vbCrLf
For i = 0 To 4
Label1.Text = Label1.Text a(i, 0) " " a(i, 1) vbCrLf
Next
For i = 0 To 3
For j = i + 1 To 4
If a(i, 0) a(j, 0) Then
Temp = a(i, 0)
a(i, 0) = a(j, 0)
a(j, 0) = Temp
Temp = a(i, 1)
a(i, 1) = a(j, 1)
a(j, 1) = Temp
End If
Next
Next
'显示排序前的数据
Label2.Text = "排序后数据:" vbCrLf
For i = 0 To 4
Label2.Text = Label2.Text a(i, 0) " " a(i, 1) vbCrLf
Next
'把第3行元素赋予X,Y
x = a(2, 0)
y = a(2, 1)
'输出X,Y
Label3.Text = "X=" x vbCrLf "Y=" y
End Sub