Link to home
Start Free TrialLog in
Avatar of Bob Schneider
Bob SchneiderFlag for United States of America

asked on

Quicker Sort

I am currently doing a lot of bubble sorting of arrays.  Is there a faster way than this:
    For x = 0 To UBound(SiteRslts, 2) - 2
        For y = x + 1 To UBound(SiteRslts, 2) - 1
            If CStr(SiteRslts(6, x)) > CStr(SiteRslts(6, y)) Then
                For z = 0 To 6
                    TempArr(z) = SiteRslts(z, x)
                    SiteRslts(z, x) = SiteRslts(z, y)
                    SiteRslts(z, y) = TempArr(z)
                Next
            End If
        Next
    Next

Open in new window

SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bob Schneider

ASKER

That is a nice resource, thank you.  It is clear that I am using an exchange sort.   Can I assume that, for a relatively small array size, the Quick Sort is a better algorithm?  If so, can I get some help applying this to the structure of my arrays.  Basically I would like to write a function that looks at a dynamic two-dimensional array such as SiteRslts(x, y) and sort based on data type at any dimension x.  The example I provided sorts based on string data types but I would also need one sorting by date, integer, and double or single.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Problem with a recordset sort is that some of the array fields are being populated via a function (to avoid getting more complicated of a join than my cerebellum can manage).  I will consider that though, thanks...

Still haven't checked out the 4Guys...solution yet...very soon..
Learned a lot about sorting.  Thanks all!