📄 form1.frm
字号:
MyArray(Index - 1) = TEMP
LookLine (12)
Label1(Index - 1) = TEMP
Call PausePro(PP)
Label1(Index).ForeColor = &H0& '黑色
Label1(Index - 1).ForeColor = &H0&
End If
LookLine (13)
If Index <> 1 Then
Label3(Index).ForeColor = &H0& '黑色
Label3(Index - 1).ForeColor = &H0&
End If
'将当前下标移到上一个值
Index = Index - 1
LookLine (14)
'用于指明重复次数的全局变量
gIterations = gIterations + 1
LookLine (15)
Loop
LookLine (16)
'将已处理的元素个数加1
NextElement = NextElement + 1
LookLine (17)
'用于指明重复次数的全局变量
gIterations = gIterations + 1
LookLine (18)
Loop
LookLine (19)
Form2.Show
Form2.Label1.Caption = "冒泡排序已经完成!"
Form2.Label2.Caption = "执行次数:" & gIterations
LookLine (20)
End Sub
'快速排序
Sub QuickSort(MyArray(), L, r)
LookLine (23)
Dim i, j, X, Y
LookLine (24)
i = L
LookLine (25)
j = r
LookLine (26)
'找出数组的中点
X = MyArray((L + r) / 2)
LookLine (27)
While (i <= j)
LookLine (28)
Label3(i).ForeColor = &HFF0000 '蓝色
Label3((L + r) / 2).ForeColor = &HFF0000
'找出比中点大的数
While (MyArray(i) < X And i < r)
LookLine (29)
i = i + 1
LookLine (30)
Label3(i - 1).ForeColor = &H0& '黑色
Label3((L + r) / 2).ForeColor = &H0&
gIterations = gIterations + 1
Wend
LookLine (31)
Label3(i).ForeColor = &H0& '黑色
Label3((L + r) / 2).ForeColor = &H0&
Label3(j).ForeColor = &HFF0000 '蓝色
Label3((L + r) / 2).ForeColor = &HFF0000
'找出比中点小的数
While (X < MyArray(j) And j > L)
LookLine (32)
j = j - 1
LookLine (33)
Label3(j + 1).ForeColor = &H0& '黑色
Label3((L + r) / 2).ForeColor = &H0&
gIterations = gIterations + 1
Wend
LookLine (34)
Label3(j).ForeColor = &H0& '黑色
Label3((L + r) / 2).ForeColor = &H0&
'互换这两个数
If (i <= j) Then
LookLine (35)
Label3(i).ForeColor = &HFF0000 '蓝色
Label3(j).ForeColor = &HFF0000
Label1(i).ForeColor = &HFF& '红色
Label1(j).ForeColor = &HFF&
Y = MyArray(i)
LookLine (36)
MyArray(i) = MyArray(j)
Label1(i) = Label1(j)
LookLine (37)
MyArray(j) = Y
Label1(j) = Y
LookLine (38)
Call PausePro(PP)
Label1(i).ForeColor = &H0& '黑色
Label1(j).ForeColor = &H0&
Label3(i).ForeColor = &H0& '黑色
Label3(j).ForeColor = &H0&
i = i + 1
LookLine (39)
j = j - 1
LookLine (40)
End If
LookLine (41)
'用于指明重复次数的全局变量
gIterations = gIterations + 1
LookLine (42)
Wend
LookLine (43)
'未完成时递归调用
If (L < j) Then Call QuickSort(MyArray(), L, j)
LookLine (44)
If (i < r) Then Call QuickSort(MyArray(), i, r)
LookLine (45)
'Form2.Show
'Form2.Label1.Caption = "快速排序已经完成!"
'Form2.Label2.Caption = "执行次数:" & gIterations
LookLine (46)
End Sub
'插入排序
Sub Insertion(MyArray())
LookLine (49)
Dim Index
LookLine (50)
Dim TEMP
LookLine (51)
Dim NextElement
LookLine (52)
'先将已处理的元素个数为最小下标加1
NextElement = LBound(MyArray) + 1
LookLine (53)
'遍历每一个元素
While (NextElement <= UBound(MyArray))
LookLine (54)
'读取当前下标
Index = NextElement
LookLine (55)
Do
LookLine (56)
'如果当前下标大于最小下标,则处理
If Index > LBound(MyArray) Then
LookLine (57)
If Index <> 1 Then
Label3(Index).ForeColor = &HFF0000 '蓝色
Label3(Index - 1).ForeColor = &HFF0000
End If
If MyArray(Index) < MyArray(Index - 1) Then
LookLine (58)
Label1(Index).ForeColor = &HFF& '红色
Label1(Index - 1).ForeColor = &HFF&
TEMP = MyArray(Index)
LookLine (59)
MyArray(Index) = MyArray(Index - 1)
Label1(Index) = Label1(Index - 1)
LookLine (60)
MyArray(Index - 1) = TEMP
Label1(Index - 1) = TEMP
LookLine (61)
Call PausePro(PP)
Label1(Index).ForeColor = &H0& '黑色
Label1(Index - 1).ForeColor = &H0&
Label3(Index).ForeColor = &H0& '黑色
Label3(Index - 1).ForeColor = &H0&
Index = Index - 1
LookLine (62)
Else
LookLine (63)
Label3(Index).ForeColor = &H0& '黑色
If Index <> 1 Then
Label3(Index - 1).ForeColor = &H0&
End If
Exit Do
LookLine (64)
End If
LookLine (65)
Else
LookLine (66)
Exit Do
LookLine (67)
End If
LookLine (68)
'用于指明重复次数的全局变量
gIterations = gIterations + 1
LookLine (69)
Loop
LookLine (70)
NextElement = NextElement + 1
LookLine (71)
'用于指明重复次数的全局变量
gIterations = gIterations + 1
LookLine (72)
Wend
LookLine (73)
Form2.Show
Form2.Label1.Caption = "插入排序已经完成!"
Form2.Label2.Caption = "执行次数:" & gIterations
LookLine (74)
End Sub
'选择排序
Sub Selection(MyArray())
LookLine (77)
Dim Index
LookLine (78)
Dim Min
LookLine (79)
Dim NextElement
LookLine (80)
Dim TEMP
LookLine (81)
NextElement = 1
LookLine (82)
While (NextElement < UBound(MyArray))
LookLine (83)
Min = UBound(MyArray)
LookLine (84)
Index = Min - 1
LookLine (85)
While (Index >= NextElement)
LookLine (86)
LookLine (86)
Label3(Min).ForeColor = &HFF0000 '蓝色
Label3(Index).ForeColor = &HFF0000
If MyArray(Index) < MyArray(Min) Then
LookLine (87)
LookLine (87)
Label3(Min).ForeColor = &H0& '黑色
Label3(Index).ForeColor = &H0&
Min = Index
LookLine (88)
End If
LookLine (89)
LookLine (89)
Label3(Min).ForeColor = &H0& '黑色
Label3(Index).ForeColor = &H0&
Index = Index - 1
LookLine (90)
gIterations = gIterations + 1
LookLine (91)
Wend
LookLine (92)
Label1(Min).ForeColor = &HFF& '红色
Label1(NextElement).ForeColor = &HFF&
TEMP = MyArray(Min)
LookLine (93)
MyArray(Min) = MyArray(NextElement)
Label1(Min) = Label1(NextElement)
LookLine (94)
MyArray(NextElement) = TEMP
Label1(NextElement) = TEMP
LookLine (95)
Call PausePro(PP)
Label1(Min).ForeColor = &H0& '黑色
Label1(NextElement).ForeColor = &H0&
NextElement = NextElement + 1
LookLine (96)
gIterations = gIterations - 1
LookLine (97)
Wend
LookLine (98)
Form2.Show
Form2.Label1.Caption = "选择排序已经完成!"
Form2.Label2.Caption = "执行次数:" & gIterations
LookLine (99)
End Sub
Sub PausePro(PP)
Dim Start, PauseTime
PauseTime = PP
Start = Timer ' 设置开始暂停的时刻。
Do While Timer < Start + PauseTime
DoEvents ' 将控制让给其他程序。
Loop
End Sub
Sub LookLine(i)
Call PausePro(PP)
Form4.List1.Selected(i) = True
End Sub
Private Sub isButton7_Click()
Form3.Show
End Sub
Private Sub isButton8_Click()
Form5.Show
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -