vb编写程序实现两个有序数组的输入,显示,并将这两个数组合并为一个新的有序数组,显示新数组。要求:
这个要怎么做? 展开
Dim a(20) As Integer, b(20) As Integer, c(40) As Integer
Dim n1 As Integer, n2 As Integer, n3 As Integer
Private Sub Command1_Click()
getdata a(), n1
Text1 = Text1 & "A数组:" & vbCrLf
xs a(), n1
End Sub
Private Sub Command2_Click()
getdata b(), n2
Text1 = Text1 & "B数组:" & vbCrLf
xs b(), n2
End Sub
Private Sub Command3_Click()
hebin a(), n1, b(), n2, c(), n3
Text1 = Text1 & "合并以后的C数组:" & vbCrLf
xs c, n3
End Sub
Sub getdata(ByRef a() As Integer, ByRef n As Integer)
While a(n) >= 0
n = n + 1
a(n) = InputBox("请输入升序的整数,以负数结束:")
Wend
n = n - 1
End Sub
Sub xs(ByRef a() As Integer, ByRef n As Integer)
For i = 1 To n
Text1 = Text1 & a(i) & " "
Next i
Text1 = Text1 & vbCrLf & vbCrLf
End Sub
Sub hebin(ByRef a() As Integer, n1 As Integer, ByRef b() As Integer, n2 As Integer, ByRef c() As Integer, ByRef n3 As Integer)
i = 1: j = 1: n3 = 1
While i <= n1 And j <= n2
If a(i) < b(j) Then
c(n3) = a(i)
i = i + 1
Else
c(n3) = b(j)
j = j + 1
End If
n3 = n3 + 1
Wend
While i <= n1
c(n3) = a(i)
i = i + 1
n3 = n3 + 1
Wend
While j <= n2
c(n3) = b(j)
j = j + 1
n3 = n3 + 1
Wend
n3 = n3 - 1
End Sub
Private Sub Form_Load()
Text1 = ""
Text2 = ""
End Sub
能具体把整个界面截图给我看吗,我试了一下老是类型不匹配。。。😂
界面都在上面了啊。--不是有图嘛。
一个文本框,三个命令按钮。
代码“复制/粘贴”就行了。