合并有序的数组a,b为数组c,将数组c排序后输出

问题描述:

合并有序的数组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

在这里
If c(i) > c(j) Then
C数组是字符比较.你要转换成数字才行.
将上面一句改成
If val(c(i)) > val(c(j)) Then
就可以了.我觉得很有道理,可是为什么还是11, 25, 56, 67, 77, 98,8, 33, 56, 93你改了吗?改成Ifval(c(i)) > val(c(j)) Then改了应该就不会这样子了。我改了,确实改了,可能还有别的错?仔细看了一下,这句c = Split(Label1.Caption & "," & Label2.Caption & ",")应该是c = Split(Label1.Caption & "," & Label2.Caption, ",")才对。