题型:综合题 题类:常考题 难易度:普通
浙江省桐庐分水高级中学2019-2020学年高三上学期信息技术第一次月考试卷
实现上述功能的VB程序如下:
Dim a(1 To 8) As Integer
Dim n As Integer
Private Sub Form_Load()
'排序前的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 = n To i + 1 Step -1
If a(j) < a(j - 1) Then
k = a(j - 1)
a(j)=a(j-1) '(2)改错
a(j) = k
'如果pos位置的数据参与交换,则更新pos值,记录pos变化情况
If pos = j Then
pos = j - 1
s = s + "→" + Str(pos)
ElseIf Then '填写代码
pos = j
s = s + "→" + Str(pos)
End If
End If
Next j
Next i
Label4.Caption = "位置变化情况:" + s
For i = 1 To n
List2.AddItem Str(a(i))
Next i
End Sub
试题篮