-
QuickSort
I looked in search for the solution but only found solutions on an array which I can do.
I want to quicksort through an object by date such as:
myObj(0).date = "10/10/2002"
myObj(1).date = "11/01/2002"
myObj(2).date = "11/22/2002"
myObj(3).date = "11/05/2002"
Thank you
-
1 Attachment(s)
-
Thank you, but will I be able to make this work with an object and get it sort by date. This is the quick sort that I am trying to work with:
Code:
Public Sub QuickSortObject(oArray As Object, inLow As Long, inHi As Long)
Dim pivot As object
Dim tmpSwap As object
Dim tmpLow As Long
Dim tmpHi As Long
tmpLow = inLow
tmpHi = inHi
pivot = oArray((inLow + inHi) \ 2)
While (tmpLow <= tmpHi)
While (oArray(tmpLow) < pivot And tmpLow < inHi)
tmpLow = tmpLow + 1
Wend
While (pivot < oArray(tmpHi) And tmpHi > inLow)
tmpHi = tmpHi - 1
Wend
If (tmpLow <= tmpHi) Then
tmpSwap = oArray(tmpLow)
oArray(tmpLow) = oArray(tmpHi)
oArray(tmpHi) = tmpSwap
tmpLow = tmpLow + 1
tmpHi = tmpHi - 1
End If
Wend
If (inLow < tmpHi) Then QuickSortObject oArray, inLow, tmpHi
If (tmpLow < inHi) Then QuickSortObject oArray, tmpLow, inHi
End Sub
-
-
You may load "reagular" array with dates, sort then and then load your UDT from that array.
-
Thanks,
Thats what I was thinking but not sure how to do it maybe:
myObj(0).date = "10/10/2002"
myObj(1).date = "11/01/2002"
myObj(2).date = "11/22/2002"
myObj(3).date = "11/05/2002"
myDate(0) = myObj(0).date
myDate(1) = myObj(1).date
myDate(2) = myObj(2).date
myDate(3) = myObj(3).date
and pass myDate but then when they sorted how do I reorganize my Object?
Thank you for you help
-
No, that would be wrong logic. Here is what you need to do:
myDate(0) = "10/10/2002"
myDate(1) = "11/01/2002"
myDate(2) = "11/22/2002"
myDate(3) = "11/05/2002"
'Sort array now
myObj(0).date = myDate(0)
myObj(1).date = myDate(1)
myObj(2).date = myDate(2)
myObj(3).date = myDate(3)