一冒泡排序
Private Sub Command1_Click()
Open "D:\15050341033\temp.txt" For Output As #1
Cls
Dim a(1 To 1000000) As Long
Dim i As Long
Dim j As Long
Dim t As Long
Dim n As Long
n = Me.Text1.Text
For i = 1 To n
a(i) = 10 + Rnd() * 100
Next i
For i = 1 To n
Print #1, a(i);
Next i
Print #1,
For i = 1 To n - 1
For j = 1 To n - i
If a(j) < a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
For i = 1 To n
Print #1, a(i);
Next i
Print #1,
Dim x As Long
Dim s As Double
s = 0
For x = 1 To n - 1
s = s + x
Next x
Print #1, "耗时为" & s
Close #1
End Sub
二选择排序
Private Sub Command1_Click()
Open "D:\15050341033\temp.txt" For Output As #1
Cls
Dim a(1 To 1000000) As Long
Dim i As Long
Dim j As Long
Dim t As Long
Dim n As Long
n = Me.Text1.Text
For i = 1 To n
a(i) = 10 + Rnd() * 100
Next i
For i = 1 To n
Print #1, a(i);
Next i
Print #1,
For i = 1 To n - 1
For j = i + 1 To n
If a(i) < a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next j
Next i
For i = 1 To n
Print #1, a(i);
Next i
Print #1,
Dim x As Long
Dim s As Double
s = 0
For x = 1 To n - 1
s = s + x
Next x
Print #1, "耗时为" & s
Close #1
End Sub
三student
Private Type student
name As String
number As Single
sex As String
age As Byte
profession As String
grade As Single
End Type
Private Sub Command1_Click()
Dim X As student
X.name = Me.Text1.Text
X.number = Me.Text1.Text
X.sex = Me.Text1.Text
X.age = Me.Text1.Text
X.profession = Me.Text1.Text
X.grade = Me.Text1.Text
Open "D:\15050341033\MYInformation.txt" For Output As #1
Print #1, X.name;
Print #1, X.number;
Print #1, X.sex;
Print #1, X.age;
Print #1, X.profession;
Print #1, X.grade;
Close #1
End Sub
四冒泡排序
Private Sub Command1_Click()
Me.Timer1.Enabled = True
Me.Command2.Enabled = True
Cls
Dim a(1 To 1000000) As Long
Dim i As Long
Dim j As Long
Dim x As Long
Dim n As Long
n = Me.Text1.Text
For i = 1 To n
a(i) = 10 + Rnd() * 100
Next i
For i = 1 To n
Print a(i);
Next i
Print
Print "排序"
For i = 1 To n - 1
For j = 1 To n - i
If a(j) < a(j + 1) Then
x = a(j): a(j) = a(j + 1): a(j + 1) = x
End If
Next j
Next i
For i = 1 To n
Print a(i);
Next i
Print
Print "OK"
Me.Command2.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim t As Integer, s As Double, v As Integer, time As Integer
If Me.Command2.Enabled = True Then
t = Val(Text2.Text)
s = t * 60
s = s - 1
Else
Print "time=" & s
Me.Timer1.Enabled = False
End If
End Sub