⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 vb 的例子
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "折半查找"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   255
      Left            =   3240
      TabIndex        =   1
      Top             =   2160
      Width           =   975
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   840
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   480
      Width           =   2055
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command1_Click()
    Dim a(1 To 15) As Integer
    a(1) = 1
    a(2) = 3: a(3) = 4: a(4) = 7: a(5) = 11
    a(6) = 23: a(7) = 33: a(8) = 35: a(9) = 57: a(10) = 111
    a(11) = 211: a(12) = 213: a(13) = 333: a(14) = 347: a(15) = 518
    Text1.Text = Search3(a, 1, 15, 518)

End Sub
 
Function Search3(a() As Integer, intStart As Integer, intEnd As Integer, b As Integer) As Integer
    Dim m As Integer, n As Integer, int1 As Integer
    m = intStart
    n = intEnd
    
    int1 = (m + n) \ 2
    If b < a(int1) Then
        n = int1 - 1
        Search3 = Search3(a, m, n, b)
    ElseIf b > a(int1) Then
        m = int1 + 1
        Search3 = Search3(a, m, n, b)
    Else
        Search3 = int1
    End If
    If m = n Then
        Search3 = m
    End If
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -