📄 5-8.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 6495
ClientLeft = 60
ClientTop = 405
ClientWidth = 4725
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
ScaleHeight = 6495
ScaleWidth = 4725
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command3
Caption = "二分检索"
Height = 495
Left = 2640
TabIndex = 4
Top = 2160
Width = 1575
End
Begin VB.CommandButton Command2
Caption = "顺序检索"
Height = 495
Left = 2640
TabIndex = 3
Top = 1440
Width = 1575
End
Begin VB.CommandButton Command1
Caption = "输入数据"
Height = 495
Left = 2640
TabIndex = 2
Top = 720
Width = 1575
End
Begin VB.ListBox List1
Height = 4155
ItemData = "5-8.frx":0000
Left = 360
List = "5-8.frx":0002
TabIndex = 1
Top = 840
Width = 1335
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "Label2"
Height = 315
Left = 2400
TabIndex = 5
Top = 3000
Width = 990
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "数组元素:"
Height = 315
Left = 360
TabIndex = 0
Top = 360
Width = 1575
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim a() As Integer, n As Integer
Private Sub Command1_Click()
List1.Clear
Dim i As Integer
n = InputBox("输入数组大小n=?")
ReDim a(1 To n)
For i = 1 To n
a(i) = InputBox("请输入第" & i & "个数据。")
List1.AddItem a(i)
Next i
End Sub
Private Sub Command2_Click()
Dim x As Integer, i As Integer
x = InputBox("输入要查找的数据x=?")
For i = 1 To n
If a(i) = x Then
Label2.Caption = "找到了!"
Exit Sub
End If
Next i
Label2.Caption = "找不到!"
End Sub
Private Sub Command3_Click()
Dim x As Integer
x = InputBox("输入要查找的数据x=?")
Dim dn As Integer, up As Integer, mid As Integer
dn = 1: up = n: mid = (dn + up) / 2
Do While dn <= up
If x = a(mid) Then
Label2.Caption = "找到了!"
Exit Sub
ElseIf x > a(mid) Then
dn = mid + 1
Else
up = mid - 1
End If
mid = (dn + up) / 2
Loop
Label2.Caption = "找不到!"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -