1个回答
展开全部
排序的方法有很多种:选择、冒泡、插入、快排、归并、堆,等等等等。
但是冒泡排序代码最简单也好理解,用这个举例吧:
Const n = 10
Dim a(10) As Integer, t As Integer, s As String
Private Sub Form_Load()
'输入
For i = 1 To n
a(i) = Val(InputBox("请输入第" + Str(i) + "个数:"))
Next i
'冒泡排序
For i = 1 To n - 1
For j = 1 To n - i
If a(j) > a(j + 1) Then
t = a(j)
a(j) = a(j + 1)
a(j + 1) = t
End If
Next j
Next i
'输出
For i = 1 To n
s = s + Str(a(i))
Next i
MsgBox s
End
End Sub
一般的算法书都有排序,抽空看一看吧
但是冒泡排序代码最简单也好理解,用这个举例吧:
Const n = 10
Dim a(10) As Integer, t As Integer, s As String
Private Sub Form_Load()
'输入
For i = 1 To n
a(i) = Val(InputBox("请输入第" + Str(i) + "个数:"))
Next i
'冒泡排序
For i = 1 To n - 1
For j = 1 To n - i
If a(j) > a(j + 1) Then
t = a(j)
a(j) = a(j + 1)
a(j + 1) = t
End If
Next j
Next i
'输出
For i = 1 To n
s = s + Str(a(i))
Next i
MsgBox s
End
End Sub
一般的算法书都有排序,抽空看一看吧
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询