vb编写一子过程insertfun(a%(),y%),它的功能是:把y值插入到有序(升序...
发布网友
发布时间:2024-10-13 16:29
我来回答
共1个回答
热心网友
时间:2024-11-02 14:47
Dim a() As Integer
Private Sub insertfun(a%(), y%)
ReDim Preserve a(UBound(a) + 1)
Dim t As Boolean
For i = 0 To UBound(a)
If y <= a(i) Then
For j = UBound(a) To i + 1 Step -1
a(j) = a(j - 1)
Next j
a(i) = y
t = True
Exit For
End If
Next i
If t = False Then a(UBound(a)) = y
End Sub
Private Sub Form_Load()
ReDim a(9)
Dim y As Integer
Me.AutoRedraw = True
For i = 0 To UBound(a)
a(i) = i * 10
Print a(i);
Next
Print
y = Val(InputBox("输入插入的数", " 输入"))
insertfun a(), y
For i = 0 To UBound(a)
Print a(i);
Next
End Sub