试题 试卷
题型:单选题 题类:常考题 难易度:普通
浙江省高中信息技术 算法及其程序实现单元检测
For i=1 To 2
k=i
For j=i+1 To 5
If d(k) < d(j) Then k=j
Next j
If k <> i Then t=d(k): d(k)=d(i) :d(i)=t
Next i
经过该程序段“加工”后,数组元素d(1)到d(5)的值依次为“44, 35, 30, 11,7”,则数组元素d(1)到d(5)的原始数据依次为( )
在列表框List1中显示排序前数据(存储在数组a中),在文本框Text1中输入初始位置(即下标值),单击“排序”按钮Command1后,在标签Label1中显示指定初始位置的数据在排序过程中的位置变化情况,排序后的数据显示在列表框List2中。程序运行界面如图所示。
实现上述功能的VB程序如下,请在横线处填上合适的代码,改正加框处的代码。
Dim a(1 To 8) As Integer
Dim n As Integer
Private Sub Form_Load()
'n = 8,排序前的8个数据存储在数组a中,并在列表框List1中显示
'代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer
Dim pos As Integer '变量pos存储指定数据的位置(既下标值)
Dim s As String '变量s存储pos变化情况
s = Text1.Text
pos = Val(Text1.Text)
For i = 1 To n - 1
For j = ⑴
If a(j) < a(j - 1) Then
⑵
a(j - 1) = a(j)
a(j) = k
'如果pos位置的数据参与交换,则更新pos值,记录pos变化情况
If pos = j Then
pos = j - 1
s = s + "→" + Str(pos)
'(3)
pos = j
End If
Label1.Caption = "位置变化情况:" + s
For i = 1 To n
List2.AddItem Str(a(i))
⑴{#blank#}1{#/blank#} ⑵{#blank#}2{#/blank#} ⑶{#blank#}3{#/blank#}
Const n =10
t = n - (n + i ) Mod 2
For j = t To i + 2 Step -2
If d(j)> d(j - 2) Then
Temp=d(j)
d(j) = d(j - 2)
d(j - 2) = temp
已知数组元素d(1)到d(10)的原始数据为1、2、3、4、5、6、7、8、9、10.程序运行后,d(10)的值为( )
Dim n, i, j, temp As Integer
Dim a(1 To 10) As Integer
n = Val(Text1.Text)
Randomize
a(1) = Int(Rnd * 20) + 1
For i = 2 To n
a(i) = Int(Rnd * 20) + 1
If a(i) > a(i - 1) Then
temp = a(i)
bot = 1 : Top = n
Do While bot <= Top
‘(1)
If temp < a(m) Then bot = m + 1 Else Top = m - 1
Loop
For k = n To bot + 1 Step -1
‘(2)
Next k
a(bot) = temp
For j = 1 To n
List1.AddItem Str(a(j))
以上程序段运行时,为了实现上述功能,加框处代码应改正为:
⑴{#blank#}1{#/blank#};⑵{#blank#}2{#/blank#}。
For i = 2 To 4
j = i: flag = False
Do While j >= 2 And Not flag If a(j) < a(j - 1) Then
t = a(j): a(j) = a(j - 1): a(j - 1) = t flag = True
End If j = j - 1
Loop Next i
数组元素a(1)到a(7)的初值依次为“8,2,7,10,6,9,5,3”,则程序运行后,元素a(1)到a(7)的值依次为( )
For i= 1 To 2
For j=5 To i+1 Step-1
If a(j) >a(i) Then
t=a(j):a(j)=a(i):a(i)=t
数组元素a(1)到a(5)的值依次为“33,24,45,16,77”,经过该程序段“加工”后,数组元素a(1)到a(5)的值依次为( )
请回答下列问题:
试题篮