# Re: 如何排序阵列?

Posted by joseph on August 12, 1998 at 22:39:48:

In Reply to: 如何排序阵列? posted by Richard on August 12, 1998 at 14:23:10:

VB没有现成的排序指令.最好是写成DLL.
如果一定要用VB写,以下的Insertion Sort可给你做个参考.

Private Sub Insertion_Sort(A() As Single, NumOfEntries As Integer)
Dim i As Integer, j As Integer
Dim temp_value As Single
If NumOfEntries < 1 Then Exit Sub
For i = 1 To NumOfEntries
temp_value = A(i)
For j = i - 1 To 0 Step -1
If temp_value < A(j) Then Exit For
A(j + 1) = A(j)
Next j
A(j + 1) = temp_value
Next i

End Sub

Follow Ups: