排序

来源:互联网 发布:tvpt50炮数据 编辑:程序博客网 时间:2024/06/07 04:00

1.随机生成100个数排序

Private Function swap(a As Integer, b As Integer)
Dim t As Integer
t = a
a = b
b = t
End Function
Private Sub Command1_Click()
  Dim a(100) As Integer
  Dim i As Integer
  For i = 1 To 100

  a(i) = 10 + Int(Rnd() * 100)

  Next i

  Dim j As Integer
  For j = 1 To 9
  For i = j + 1 To 100
      If a(j) < a(i) Then
         swap a(j), a(i)
      End If
   Next i
   Next j
   For i = 1 To 100
       Print a(i);
   Next i
   Print
End Sub

2.随机生成1000个数

Private Function swap(a As Integer, b As Integer)
Dim t As Integer
t = a
a = b
b = t
End Function
Private Sub Command1_Click()
  Dim a(1000) As Integer
  Dim i As Integer
  For i = 1 To 1000
  a(i) = 10 + Int(Rnd() * 100)

  Next i

  Dim j As Integer
  For j = 1 To 9
  For i = j + 1 To 1000
      If a(j) < a(i) Then
         swap a(j), a(i)
      End If
   Next i
   Next j
   For i = 1 To 1000
       Print a(i);
   Next i
   Print
End Sub

 

0 0
原创粉丝点击