Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim arr(6) As Double
arr(1) = CDbl(TextBox1.Text)
arr(2) = CDbl(TextBox2.Text)
arr(3) = CDbl(TextBox3.Text)
arr(4) = CDbl(TextBox4.Text)
arr(5) = CDbl(TextBox5.Text)
arr(6) = CDbl(TextBox6.Text)
Call BubbleSort(arr)
TextBox1.Text = CStr(arr(1))
TextBox2.Text = CStr(arr(2))
TextBox3.Text = CStr(arr(3))
TextBox4.Text = CStr(arr(4))
TextBox5.Text = CStr(arr(5))
TextBox6.Text = CStr(arr(6))
End Sub
Sub BubbleSort(ByVal List() As Double)
Dim first, last, temp As Double
Dim i, j As Integer
first = LBound(List)
Last = UBound(List)
For i = first To last - 1
For j = i + 1 To last
If List(i) > List(j) Then
temp = List(j)
List(j) = List(i)
List(i) = temp
End If
Next
Next
End Sub
Dim x(10) As Integer
Dim m As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
m = 0
End Sub
Private Sub btn_continue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn.Click
Try
If btn.Text = "继续" Then
x(m) = Convert.ToInt32(txt_input.Text)
m = m + 1
txt_input.Clear()
txt_input.Focus()
If m > 9 Then
btn.Text = "排序"
End If
Else
Dim i, j As Integer
Dim t As Integer
For i = 0 To 9
For j = 0 To 9 - i
If x(j) <= x(j + 1) Then
t = x(j)
x(j) = x(j + 1)
x(j + 1) = t
End If
Next
Next
For i = 0 To 9
Label2.Text += x(i).ToString + " "
Next
btn.Enabled = False
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
[此贴子已经被作者于2006-3-21 16:46:39编辑过]