VB题,高手帮忙作完

来源:百度知道 编辑:UC知道 时间:2024/06/25 15:54:46
'阅读程序并将问号处补充完整,使其实现以下功能:
'输入一个数,将其插入到递增的有序数列中,并使插入后的序列仍然有序
''注意:除带?语句外,不要修改其他内容。

Private Sub Command1_Click()
'?
Dim i As Integer, n As Integer, m As Integer
a = Array(1, 9, 12, 13, 45, 56, 67, 78, 89, 95, 96, 102)
n = UBound(a)
'ReDim ?
m = Val(InputBox("输入要插入的数"))
For i = UBound(a) - 1 To 0 Step -1
If m < a(i) Then
a(i + 1) = a(i)
'?
Else
'?
Exit For
End If
Next i
For i = 0 To UBound(a)
Print a(i);
Next i

End Sub

题目有错
'输入一个数,将其插入到递增的有序数列中,并使插入后的序列仍然有序
''注意:除带?语句外,不要修改其他内容。

Private Sub Command1_Click()
Dim i As Integer, n As Integer, m As Integer
Dim a '应该在这里?
a = Array(1, 9, 12, 13, 45, 56, 67, 78, 89, 95, 96, 102)
n = UBound(a)
ReDim Preserve a(n + 1)
m = Val(InputBox("输入要插入的数"))
For i = UBound(a) - 1 To 0 Step -1
If m < a(i) Then
a(i + 1) = a(i)
'?这里不需要
Else
a(i + 1) = m
Exit For
End If
Next i
For i = 0 To UBound(a)
Print a(i);
Next i

End Sub

四处分别是:

Dim a

(ReDim) preserve a(n + 1)

a(i) = m

a(i + 1) = m