题型:填空题 题类:常考题 难易度:普通
高中信息技术——排序算法及程序实现(浙江专用)
实现上述功能的VB程序如下,但加框处代码有错,请改正。
Dim a(1 To 8)As Integer
Dim n As Integer
Private Sub Form_Load()
a(1)= 30:a(2)= 47:a(3)= 30:a(4)= 72
a(5)= 70:a(6)= 23:a(7)= 99:a(8)= 24
n = 8
For i = 1 To 8
List 1.Addltem a(i)
Next i
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer
Dim pos As Integer
Dim s As String
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
‘⑴
a(j-1)= a(j)
a(j)= k
'如果pos位置的数据参与交换,则更新pos值,记录pos变化位置
If pos = j Then
pos = j-1
s = s + " →" + Str(pos)
‘⑵
pos = j
s = s + " →" + Str(pos)
End If
End If
Next j
Next i
Label1.Caption = "位置变化情况:" +s
For i = 1 To n
List2.AddItem Str(a(i))
Next i
End Sub
⑴ ⑵
试题篮