vb.net 求一个二维数组排序代码 详谈
2013-11-18
展开全部
Sub QuickSort(MyArray() As Single, L, R)
Dim i As Integer, j As Integer, X As Single, Y As Single, M As Single
i = L
j = R
'找出数组的中点
M = MyArray((L + R) / 2, 0)
While (i <= j)
'找出比中点大的数
While (MyArray(i, 0) < M And i < R)
i = i + 1
Wend
'找出比中点小的数
While (M < MyArray(j, 0) And j > L)
j = j - 1
Wend
'互换这两个数
If (i <= j) Then
X = MyArray(i, 0)
Y = MyArray(i, 1)
MyArray(i, 0) = MyArray(j, 0)
MyArray(i, 1) = MyArray(j, 1)
MyArray(j, 0) = X
MyArray(j, 1) = Y
i = i + 1
j = j - 1
End If
Wend
'未完成时递归调用
If (L < j) Then Call QuickSort(MyArray(), L, j)
If (i < R) Then Call QuickSort(MyArray(), i, R)
End Sub
Dim i As Integer, j As Integer, X As Single, Y As Single, M As Single
i = L
j = R
'找出数组的中点
M = MyArray((L + R) / 2, 0)
While (i <= j)
'找出比中点大的数
While (MyArray(i, 0) < M And i < R)
i = i + 1
Wend
'找出比中点小的数
While (M < MyArray(j, 0) And j > L)
j = j - 1
Wend
'互换这两个数
If (i <= j) Then
X = MyArray(i, 0)
Y = MyArray(i, 1)
MyArray(i, 0) = MyArray(j, 0)
MyArray(i, 1) = MyArray(j, 1)
MyArray(j, 0) = X
MyArray(j, 1) = Y
i = i + 1
j = j - 1
End If
Wend
'未完成时递归调用
If (L < j) Then Call QuickSort(MyArray(), L, j)
If (i < R) Then Call QuickSort(MyArray(), i, R)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询