📄 冒泡法排序.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3075
ClientLeft = 60
ClientTop = 465
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3075
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "生成数组数组排序"
Height = 735
Left = 2520
TabIndex = 4
Top = 1920
Width = 855
End
Begin VB.TextBox Text2
Height = 375
Left = 1200
TabIndex = 3
Top = 840
Width = 3015
End
Begin VB.TextBox Text1
Height = 375
Left = 1200
TabIndex = 2
Top = 240
Width = 3015
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "排序后"
Height = 180
Left = 240
TabIndex = 1
Top = 840
Width = 540
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "原始数组"
Height = 180
Left = 240
TabIndex = 0
Top = 360
Width = 720
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Base 1
Private Sub Command1_Click()
Dim a(10) As Integer, i As Integer
Randomize
For i = 1 To 10
a(i) = Int(100 * Rnd) + 1
Text1.Text = Text1.Text & Str(a(i))
Next i
Call bubble_sort(a)
For i = 1 To 10
Text2.Text = Text2.Text & Str(a(i))
Next i
End Sub
Private Sub bubble_sort(a() As Integer)
Dim i As Integer, temp As Integer
Dim ub As Integer, switch As Boolean
ub = UBound(a)
switch = True
Do While switch
switch = False
ub = ub - 1
For i = 1 To ub
If a(i) > a(i + 1) Then
switch = True
temp = a(i)
a(i) = a(i + 1)
a(i + 1) = temp
End If
Next i
Loop
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -