Solved

Quicker Sort

Posted on 2013-01-26
7
279 Views
Last Modified: 2013-02-03
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

0
Comment
Question by:Bob Schneider
7 Comments
 
LVL 84

Assisted Solution

by:ozo
ozo earned 125 total points
ID: 38822245
0
 

Author Comment

by:Bob Schneider
ID: 38822390
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.
0
 
LVL 37

Assisted Solution

by:TommySzalapski
TommySzalapski earned 125 total points
ID: 38822787
For a relatively small array size, it doesn't really matter what sort you use.
Quicksort will be a lot faster than Bubblesort (which is what you are using). So will any of the nlg(n) sorts.

However, if you are using VB/asp, then why not use the built in sorts?
You could use IComparator or the Array.OrderBy function and pass it the element that you want to sort by. (I'm not a VB programmer so I don't know the exact syntax off the top of my head).
This may help
http://stackoverflow.com/questions/1751768/sort-an-array-of-structures-in-net
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 35

Accepted Solution

by:
Robert Schutt earned 200 total points
ID: 38822830
0
 
LVL 28

Assisted Solution

by:sybe
sybe earned 50 total points
ID: 38835350
It is probably much faster to sort it in a recordset. You can create a ADODB.RecordSet on the fly and use the Sort Property on the recordset.
0
 

Author Comment

by:Bob Schneider
ID: 38835800
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..
0
 

Author Closing Comment

by:Bob Schneider
ID: 38848654
Learned a lot about sorting.  Thanks all!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tidtcpserver connection lost handle 2 70
If-Then-Else ASP problem 6 49
Auto-indent certain lines in Notepad++ 10 20
Issues with Insert statement 12 8
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now