Function BubbleSort1(ZHArray, XArray, YArray, ZArray As Variant)
'方法 2: 气泡排序。根据
http://support.microsoft.com/网站提供的代码修改
'思路是根据一维数组排序,扩展到其他列也跟着排序,思路和单元格排序操作一致。
Dim temp As Variant
Dim temp1 As Variant
Dim Temp2 As Variant
Dim Temp3 As Variant
Dim i As Integer
Dim NoExchanges As Integer
Dim First As Integer, Last As Integer
First = LBound(ZHArray) '取数组上界
Last = UBound(ZHArray) '取数组下界
' Loop until no more "exchanges" are made.
Do
NoExchanges = True
' Loop through each element in the array.
For i = First To Last - 1
' If the element is greater than the element
' following it, exchange the two elements.
If ZHArray(i) > ZHArray(i + 1) Then
NoExchanges = False
temp = ZHArray(i) '桩号
ZHArray(i) = ZHArray(i + 1)
ZHArray(i + 1) = temp
temp1 = XArray(i) 'X坐标
Temp2 = YArray(i) 'Y坐标
Temp3 = ZArray(i) 'z坐标
XArray(i) = XArray(i + 1)
YArray(i) = YArray(i + 1)
ZArray(i) = ZArray(i + 1)
XArray(i + 1) = temp1
YArray(i + 1) = Temp2
ZArray(i + 1) = Temp3
End If
Next i
Loop While Not (NoExchanges)
End Function