Solved

# Quicker Sort

Posted on 2013-01-26
277 Views
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
``````
0
Question by:Bob Schneider

LVL 84

Assisted Solution

ozo earned 125 total points
0

Author Comment

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

TommySzalapski earned 125 total points
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

LVL 35

Accepted Solution

Robert Schutt earned 200 total points
0

LVL 28

Assisted Solution

sybe earned 50 total points
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

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

Learned a lot about sorting.  Thanks all!
0

## Featured Post

### Suggested Solutions

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …