作业帮 > 数学 > 作业

把两个按升序排列的数列a(1),a(2),…,a(n)和b(1),b(2),…,b(m),合并成一个仍为升序排列的新数列

来源:学生作业帮 编辑:大师作文网作业帮 分类:数学作业 时间:2024/11/17 06:57:48
把两个按升序排列的数列a(1),a(2),…,a(n)和b(1),b(2),…,b(m),合并成一个仍为升序排列的新数列.
把两个按升序排列的数列a(1),a(2),…,a(n)和b(1),b(2),…,b(m),合并成一个仍为升序排列的新数列
你没说用什么编啊,我是vb编的

Private Sub Command1_Click()
Dim c() As Single
al = LBound(a)
ae = UBound(a)
bl = LBound(b)
be = UBound(b) - bl
ReDim c(ae - al + 1 + be)
cl = 0
Do
If al > ae Then
c(cl) = b(bl)
cl = cl + 1
bl = bl + 1
ElseIf bl > be Then
c(cl) = a(al)
cl = cl + 1
al = al + 1
ElseIf a(al) < b(bl) Then
c(cl) = a(al)
cl = cl + 1
al = al + 1
Else
c(cl) = b(bl)
cl = cl + 1
bl = bl + 1
End If
Loop Until al > ae And bl > be
end sub

Private Sub Command1_Click()
Dim a(1 To 100) As Integer
Dim b() As Integer
List1.Clear
List2.Clear
For i = 1 To 100
a(i) = Rnd() * 21
List1.AddItem a(i)
If a(i) 0 Then
bn = bn + 1
ReDim Preserve b(bn)
b(bn) = a(i)
List2.AddItem a(i)
End If
Next i
Label1 = "共产生了" & 100 - bn & "个零."
End Su