试题

试题 试卷

logo

题型:综合题 题类:常考题 难易度:困难

浙江省杭州地区重点中学2018-2019学年高二下学期信息技术期中考试试卷

罗列对分查找中可能查到的中点。对分查找是我们常用的查找方式。在对分查找过程中,计算中点是非常重要的步骤。以下程序实现了“罗列对分查找中可能查到的中点”的功能。算法如下:用户在文本框Text1中输入模拟对分查找数据的个数n,单击“产生随机数并升序排列”按钮,在List1中显示n个不重复且已经升序排列的数(范围[1,100]),单击“可能查到的中点”,在list2中分行显示各个可能查到的中点

(1)、实现上述功能的VB程序如下,请在划线处填入合适代码。

Private Sub Command1_Click()

Dim i As Integer

Randomize

For i = 1 To 100

  f(i) = False

Next i

n = Val(Text1.Text)

For i = 1 To n

  t = Int(Rnd * 100 + 1)

  Do While f(t) = True

  Loop

  f(t) = True

Next i

j = 0

For i = 1 To 100

  If  Then

    j = j + 1

a(j) = i

List1.AddItem Str(i)

  End If

Next i

End Sub

Private Sub Command2_Click()

Dim b(1 To 100) As Integer, k As Integer, c As Integer, max As Integer

Dim s As String

Dim j As Integer

n = Val(Text1.Text)

max = 0

For k = 1 To n

 i = 1: j = n: c = 0

 Do While i <= j

  m = (i + j) \ 2: c = c + 1

  If c > max Then max = c

  If m = k Then b(m) = c: Exit Do

  If m < k Then i = m + 1 Else j = m - 1

 Loop

Next k

For i = 1 To max

 s = ""

 For j = 1 To n

  If  Then

   s = s + Str(a(j))

  Else

   s = s + ""

  End If

 Next j

List2.AddItem s

Next i

End Sub

(2)、当数据是11,22,33,44,55,66,77,88,99时,第3行第3个数为
举一反三
返回首页

试题篮