S
stephenc
I would like to indicate the progress of my quicksort. I understand that, per
iteration, progress can be calculated by using something like this:
myRange = iUpper - iLower + 1
Progress = Round((myRange * Log(myRange))/3) + (myRange/3)
....but I can't get any sensible values from it, I am sure I am missing
something major, and I confess my mathematical abilities are not up to the
task.
Can anyone help me to understand what I should be doing?
My quicksort takes a public 2 dimensional (x,y) array and sorts just on the
y part. The array is called FA, and varies in size, but here is how to call
my code assuming FA has 1000 records (0-999):
Call QuickSortFA(0, 999)
Here is my quicksort code:
Public Sub QuickSortFA(Optional iLower As Integer, Optional iUpper As Integer)
Dim iLowerValue As Integer
Dim iUpperValue As Integer
Dim vTest As String
Dim iMidValue As Integer
Dim vTemp As Variant
If iLower < iUpper Then
iMidValue = Int((iLower + iUpper) / 2)
vTest = LCase(FA(1, iMidValue))
iLowerValue = iLower
iUpperValue = iUpper
Do
Do While LCase(FA(1, iLowerValue)) < vTest
iLowerValue = iLowerValue + 1
Loop
Do While LCase(FA(1, iUpperValue)) > vTest
iUpperValue = iUpperValue - 1
Loop
If iLowerValue <= iUpperValue Then
vTemp = FA(0, iUpperValue)
FA(0, iUpperValue) = FA(0, iLowerValue)
FA(0, iLowerValue) = vTemp
vTemp = FA(1, iUpperValue)
FA(1, iUpperValue) = FA(1, iLowerValue)
FA(1, iLowerValue) = vTemp
iLowerValue = iLowerValue + 1
iUpperValue = iUpperValue - 1
End If
Loop Until iLowerValue > iUpperValue
If iUpperValue <= iMidValue Then
Call QuickSortFA(iLower, iUpperValue)
Call QuickSortFA(iLowerValue, iUpper)
Else
Call QuickSortFA(iLowerValue, iUpper)
Call QuickSortFA(iLower, iUpperValue)
End If
End If
End Sub
iteration, progress can be calculated by using something like this:
myRange = iUpper - iLower + 1
Progress = Round((myRange * Log(myRange))/3) + (myRange/3)
....but I can't get any sensible values from it, I am sure I am missing
something major, and I confess my mathematical abilities are not up to the
task.
Can anyone help me to understand what I should be doing?
My quicksort takes a public 2 dimensional (x,y) array and sorts just on the
y part. The array is called FA, and varies in size, but here is how to call
my code assuming FA has 1000 records (0-999):
Call QuickSortFA(0, 999)
Here is my quicksort code:
Public Sub QuickSortFA(Optional iLower As Integer, Optional iUpper As Integer)
Dim iLowerValue As Integer
Dim iUpperValue As Integer
Dim vTest As String
Dim iMidValue As Integer
Dim vTemp As Variant
If iLower < iUpper Then
iMidValue = Int((iLower + iUpper) / 2)
vTest = LCase(FA(1, iMidValue))
iLowerValue = iLower
iUpperValue = iUpper
Do
Do While LCase(FA(1, iLowerValue)) < vTest
iLowerValue = iLowerValue + 1
Loop
Do While LCase(FA(1, iUpperValue)) > vTest
iUpperValue = iUpperValue - 1
Loop
If iLowerValue <= iUpperValue Then
vTemp = FA(0, iUpperValue)
FA(0, iUpperValue) = FA(0, iLowerValue)
FA(0, iLowerValue) = vTemp
vTemp = FA(1, iUpperValue)
FA(1, iUpperValue) = FA(1, iLowerValue)
FA(1, iLowerValue) = vTemp
iLowerValue = iLowerValue + 1
iUpperValue = iUpperValue - 1
End If
Loop Until iLowerValue > iUpperValue
If iUpperValue <= iMidValue Then
Call QuickSortFA(iLower, iUpperValue)
Call QuickSortFA(iLowerValue, iUpper)
Else
Call QuickSortFA(iLowerValue, iUpper)
Call QuickSortFA(iLower, iUpperValue)
End If
End If
End Sub