合并有序的数组a,b为数组c,将数组c排序后输出Private Sub Command1_Click()Dim cc = Split(Label1.Caption & "," & Label2.Caption & ",")For i = 0 To UBound(c) - 1For j = i To UBound(c)If c(i) > c(j) Thent = c(i)c(i) = c(j)c(j) = tEnd IfNex

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/24 07:43:08
合并有序的数组a,b为数组c,将数组c排序后输出PrivateSubCommand1_Click()Dimcc=Split(Label1.Caption&","&Label2.Caption&",")

合并有序的数组a,b为数组c,将数组c排序后输出Private Sub Command1_Click()Dim cc = Split(Label1.Caption & "," & Label2.Caption & ",")For i = 0 To UBound(c) - 1For j = i To UBound(c)If c(i) > c(j) Thent = c(i)c(i) = c(j)c(j) = tEnd IfNex
合并有序的数组a,b为数组c,将数组c排序后输出
Private Sub Command1_Click()
Dim c
c = Split(Label1.Caption & "," & Label2.Caption & ",")
For i = 0 To UBound(c) - 1
For j = i To UBound(c)
If c(i) > c(j) Then
t = c(i)
c(i) = c(j)
c(j) = t
End If
Next j
Next i
Label3.Caption = Join(c,",")
End Sub
Private Sub Form_Load()
Dim a,b
a = Array(11,25,56,67,77,98)
b = Array(8,33,56,93)
Label1.Caption = Join(a,",")
Label2.Caption = Join(b,",")
End Sub
为什么输出的c不是排好顺序的,是11,25,56,67,77,98,8,33,56,93

合并有序的数组a,b为数组c,将数组c排序后输出Private Sub Command1_Click()Dim cc = Split(Label1.Caption & "," & Label2.Caption & ",")For i = 0 To UBound(c) - 1For j = i To UBound(c)If c(i) > c(j) Thent = c(i)c(i) = c(j)c(j) = tEnd IfNex
在这里
If c(i) > c(j) Then
C数组是字符比较.你要转换成数字才行.
将上面一句改成
If val(c(i)) > val(c(j)) Then
就可以了.