VB 对二维字符串数组排序
答案:1 悬赏:80 手机版
解决时间 2021-03-15 01:11
- 提问者网友:蓝莓格格巫
- 2021-03-14 02:31
VB 对二维字符串数组排序
最佳答案
- 五星知识达人网友:酒醒三更
- 2021-03-14 03:50
给你个参考程序朋友
Option Base 1
Private Sub Form_Click()
Dim a$(2, 4), b$(8), k%
'给二维数组赋值
For i = 1 To 2
For j = 1 To 4
a(i, j) = InputBox("请输入第" & i & "行" & "第" & j & "列英文单词")
k = k + 1: b(k) = a(i, j) '同时将值赋给一维数组
Next j
Next i
Print "原始数组为:"
For i = 1 To 2
For j = 1 To 4
Print a(i, j) & " ";
Next j
Print
Next i
'将字符串排序
For i = 1 To 8
For j = 1 To 8 - i
If b(j) > b(j + 1) Then
t = b(j): b(j) = b(j + 1): b(j + 1) = t
End If
Next j
Next i
'重新赋回原数组并输出
Print "排序后为:"
k = 0
For i = 1 To 2
For j = 1 To 4
k = k + 1
a(i, j) = b(k)
Print a(i, j) & " ";
Next j
Print
Next i
End Sub
Option Base 1
Private Sub Form_Click()
Dim a$(2, 4), b$(8), k%
'给二维数组赋值
For i = 1 To 2
For j = 1 To 4
a(i, j) = InputBox("请输入第" & i & "行" & "第" & j & "列英文单词")
k = k + 1: b(k) = a(i, j) '同时将值赋给一维数组
Next j
Next i
Print "原始数组为:"
For i = 1 To 2
For j = 1 To 4
Print a(i, j) & " ";
Next j
Next i
'将字符串排序
For i = 1 To 8
For j = 1 To 8 - i
If b(j) > b(j + 1) Then
t = b(j): b(j) = b(j + 1): b(j + 1) = t
End If
Next j
Next i
'重新赋回原数组并输出
Print "排序后为:"
k = 0
For i = 1 To 2
For j = 1 To 4
k = k + 1
a(i, j) = b(k)
Print a(i, j) & " ";
Next j
Next i
End Sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯