Results 1 to 7 of 7

Thread: QuickSort

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    USA
    Posts
    95

    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

  2. #2
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    See attachments.
    Attached Files Attached Files
    Roy

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    USA
    Posts
    95
    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
    Last edited by landon11; Nov 22nd, 2002 at 03:09 PM.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    USA
    Posts
    95
    whoops

  5. #5
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    You may load "reagular" array with dates, sort then and then load your UDT from that array.
    Roy

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    USA
    Posts
    95
    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

  7. #7
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    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)
    Roy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width