- 积分
- 10513
- 明经币
- 个
- 注册时间
- 2002-6-3
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2004-1-8 19:35:00
|
显示全部楼层
这个不知道是否满足。
- Option Explicit
- ' 第2维:0索引,1值
- Dim b(0 To 3, 0 To 1) As Double
- Sub test()
- ' 生成初始数据
- Dim n As Integer
- n = 5000
- Dim a() As Double
- ReDim a(0 To n)
- Dim i As Integer
- For i = 0 To n
- a(i) = 1000 * Rnd
- Next
-
- ' 赋值
- b(0, 0) = 1
- b(0, 1) = a(0)
- b(1, 0) = 2
- b(1, 1) = a(1)
- b(2, 0) = 3
- b(2, 1) = a(2)
- ' 排序
- MinEx 4, a(3)
- Debug.Print b(0, 0) & ": " & b(0, 1)
- Debug.Print b(1, 0) & ": " & b(1, 1)
- Debug.Print b(2, 0) & ": " & b(2, 1)
- ' 排序
- For i = 4 To n
- MinEx i, a(i)
- Next
- Debug.Print b(0, 0) & "," & b(0, 1)
- Debug.Print b(1, 0) & "," & b(1, 1)
- Debug.Print b(2, 0) & "," & b(2, 1)
- End Sub
- Sub MinEx(ByVal Index As Long, ByVal Value As Double)
- b(3, 0) = Index ' 索引
- b(3, 1) = Value ' 值
-
- ' 数组排序
- Dim t As Double
- Dim i As Integer
- Dim j As Integer
- For i = 0 To 2
- For j = i + 1 To 3
- If b(i, 1) > b(j, 1) Then
- t = b(i, 0)
- b(i, 0) = b(j, 0)
- b(j, 0) = t
- t = b(i, 1)
- b(i, 1) = b(j, 1)
- b(j, 1) = t
- End If
- Next
- Next
- End Sub
|
|