|
楼主 |
发表于 2018-9-6 07:53
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 onthetrip 于 2018-9-6 07:59 编辑
贴一下代码- Const DATA = 1
- Const L_NEXT = 2
- Const L_PREV = 3
- Sub TestSpeed()
- Dim aData_1(), aData_2(), aList()
- aData_1 = Array(6, 5, 8, 7, 9, 10)
- ReDim aData_2(1 To UBound(aData_1) + 1)
- For i = 0 To UBound(aData_1)
- aData_2(i + 1) = aData_1(i)
- Next
- ReDim aList(0 To UBound(aData_2), 1 To 3)
- aList(0, L_NEXT) = 1
- For i = 1 To UBound(aData_2)
- aList(i, DATA) = aData_2(i): aList(i, L_NEXT) = i + 1: aList(i, L_PREV) = i - 1
- Next
- Call QuickSortByLinkedList(aList, 1, UBound(aList))
- End Sub
- Sub QuickSortByLinkedList(aList(), nLeft, nRight)
- Dim i&, gKey!, nKeyIndex&, nPoint&
- If nLeft = nRight Then
- Exit Sub
- End If
- nKeyIndex = nLeft
- gKey = aList(nKeyIndex, DATA)
- i = nLeft
- Do
- i = aList(i, L_NEXT)
- If aList(i, DATA) <= gKey Then
- nPoint = aList(i, L_PREV)
- aList(aList(i, L_PREV), L_NEXT) = aList(i, L_NEXT)
- If i <> nRight Then
- aList(aList(i, L_NEXT), L_PREV) = aList(i, L_PREV)
- Else
- nRight = aList(i, L_PREV)
- End If
- aList(i, L_PREV) = aList(nKeyIndex, L_PREV)
- aList(i, L_NEXT) = nKeyIndex
- If nKeyIndex <> nLeft Then
- aList(aList(nKeyIndex, L_PREV), L_NEXT) = i
- Else
- If aList(0, L_NEXT) = nLeft Then
- aList(0, L_NEXT) = i
- End If
- Debug.Print aList(aList(nKeyIndex, L_PREV), L_NEXT) '????е????Call????????????3
- nLeft = i
- Debug.Print aList(aList(nKeyIndex, L_PREV), L_NEXT) '???????????nLeft=i??????????4???
- End If
- aList(nKeyIndex, L_PREV) = i
- i = nPoint
- End If
- If i = nRight Then Exit Do
- Loop
- If nLeft <> nKeyIndex Then
- Call QuickSortByLinkedList(aList, nLeft, aList(nKeyIndex, L_PREV))
- End If
- If nKeyIndex <> nRight Then
- Call QuickSortByLinkedList(aList, aList(nKeyIndex, L_NEXT), nRight)
- End If
- End Sub
复制代码 注释不知道为什么是乱码。
就是代码中的debug.print语句,在执行nLeft=i后,值就变了,不解。
|
|