合并有序的数组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
就可以了.
举一反三
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
最新试题
热门考点