二维数组排序 vb.net
moto(0).data1=1:moto(0).data2=5想把这个二维数组以data1排升序moto(1).data1=2:moto(1).data2=55当出现同样...
moto(0).data1 = 1 : moto(0).data2 = 5 想把这个二维数组以data1排升序
moto(1).data1 = 2 : moto(1).data2 = 55 当出现同样的值时,
moto(2).data1 = 3 : moto(2).data2 = 33 data2值大的那个放上面
moto(3).data1 = 4 : moto(3).data2 = 22
moto(4).data1 = 5 : moto(4).data2 = 21
moto(5).data1 = 5 : moto(5).data2 = 11
moto(6).data1 = 6 : moto(6).data2 = 84
moto(7).data1 = 7 : moto(7).data2 = 48
moto(8).data1 = 8 : moto(8).data2 = 19
moto(9).data1 = 9 : moto(9).data2 = 20
moto(10).data1 = 10 : moto(10).data2 = 78
moto(11).data1 = 12 : moto(11).data2 = 66
moto(12).data1 = 1 : moto(12).data2 = 77
moto(13).data1 = 25 : moto(13).data2 = 33
moto(14).data1 = 60 : moto(14).data2 = 11
moto(15).data1 = 100 : moto(15).data2 = 72 展开
moto(1).data1 = 2 : moto(1).data2 = 55 当出现同样的值时,
moto(2).data1 = 3 : moto(2).data2 = 33 data2值大的那个放上面
moto(3).data1 = 4 : moto(3).data2 = 22
moto(4).data1 = 5 : moto(4).data2 = 21
moto(5).data1 = 5 : moto(5).data2 = 11
moto(6).data1 = 6 : moto(6).data2 = 84
moto(7).data1 = 7 : moto(7).data2 = 48
moto(8).data1 = 8 : moto(8).data2 = 19
moto(9).data1 = 9 : moto(9).data2 = 20
moto(10).data1 = 10 : moto(10).data2 = 78
moto(11).data1 = 12 : moto(11).data2 = 66
moto(12).data1 = 1 : moto(12).data2 = 77
moto(13).data1 = 25 : moto(13).data2 = 33
moto(14).data1 = 60 : moto(14).data2 = 11
moto(15).data1 = 100 : moto(15).data2 = 72 展开
1个回答
展开全部
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询