【正文】
Array) iUBound = UBound(lngArray) 39。Create swap array ReDim arrTemp(iLBound To iUBound) iMax = amp。H80000000 39。Find largest For iLoop = iLBound To iUBound If lngArray(iLoop) iMax Then iMax = lngArray(iLoop) Next iLoop 39。Calculate how many sorts are needed Do While iMax iSorts = iSorts + 1 iMax = iMax \ 256 Loop iMax = 1 39。Do the sorts For iLoop = 1 To iSorts If iLoop And 1 Then 39。Odd sort src to dest InnerRadixSort lngArray, arrTemp, iLBound, iUBound, iMax Else 39。Even sort dest to src InnerRadixSort arrTemp, lngArray, iLBound, iUBound, iMax End If 39。Next sort factor iMax = iMax * 256 Next iLoop 39。If odd number of sorts we need to swap the arrays If (iSorts And 1) Then For iLoop = iLBound To iUBound lngArray(iLoop) = arrTemp(iLoop) Next iLoop End IfEnd SubPrivate Sub InnerRadixSort(ByRef lngSrc() As Long, ByRef lngDest() As Long, ByVal iLBound As Long, ByVal iUBound As Long, ByVal iDivisor As Long) Dim arrCounts(255) As Long Dim arrOffsets(255) As Long Dim iBucket As Long Dim iLoop As Long 39。Count the items for each bucket For iLoop = iLBound To iUBound iBucket = (lngSrc(iLoop) \ iDivisor) And 255 arrCounts(iBucket) = arrCounts(iBucket) + 1 Next iLoop 39。Generate offsets For iLoop = 1 To 255 arrOffsets(iLoop) = arrOffsets(iLoop 1) + arrCounts(iLoop 1) + iLBound Next iLoop 39。Fill the buckets For iLoop = iLBound To iUBound iBucket = (lngSrc(iLoop) \ iDivisor) And 255 lngDest(arrOffsets(iBucket)) = lngSrc(iLoop) arrOffsets(iBucket) = arrOffsets(iBucket) + 1 Next iLoopEnd Sub10 Shaker SortPublic Sub ShakerSort(ByRef lngArray() As Long)Dim iLower As LongDim iUpper As LongDim iInner As LongDim iLBound As LongDim iUBound As LongDim iTemp As LongDim iMax As LongDim iMin As LongiLBound = LBound(lngArray)iUBound = UBound(lngArray)iLower = iLBound 1iUpper = iUBound + 1Do While iLower iUpperiLower = iLower + 1iUpper = iUpper 1iMax = iLoweriMin = iLower39。Find the largest and smallest values in the subarrayFor iInner = iLower To iUpperIf lngArray(iInner) lngArray(iMax) TheniMax = iInnerElseIf lngArray(iInner) lngArray(iMin) TheniMin = iInnerEnd IfNext iInner39。Swap the largest with last slot of the subarrayiTemp = lngArray(iMax)lngArray(iMax) = lngArray(iUpper)lngArray(iUpper) = iTemp39。Swap the smallest with the first slot of the subarrayiTemp = lngArray(iMin)lngArray(iMin) = lngArray(iLower)lngArray(iLower) = iTempLoopEnd Sub