Re: non-recursive quicksort for 2-D arrays?



On 5 May 2006 00:56:51 -0700, bart.smissaert@xxxxxxxxx wrote:

Had a look at that one, but thought it was for 1-D arrays.
Will have a look again.
Have you tried it?

A good sort algorithm has three components :-

1) Sort Code
2) Compare Code
3) Swap Code

One can RaiseEvent to do the latter two
- or even use a crafty CallBack

The guts of the sorting algorithm need know nothing about what it is
sorting.

From earlier posts of yours and Mike's it is pretty obvious that you
should be sorting a load of record numbers and finally re-organizing
the data in one pass

I use the Shell Sort - and have done since 1984

It is not as fast as the QuickSort algorithm (by a minute fraction)
and is totally Stack Safe - unlike QuickSort

Here is a Class :-

------------ Start of cSort.cls ---------------

Option Explicit: DefObj A-Z

Public Event Compare(I&, J&, IsGreater As Boolean)
Public Event Swap(I&, J&)

' ##########################################################
'
' Sort 1 to Max items
'
Public Sub Sort(Max&)
Dim L9&, L8&, Gap&, IsGreater As Boolean

Gap = Int(Max / 2) + 1
While Gap > 0
For L9 = 1 To Max - Gap
For L8 = L9 To 1 Step -Gap
RaiseEvent Compare(L8, L8 + Gap, IsGreater)
If IsGreater Then
RaiseEvent Swap(L8, L8 + Gap)
Else
L8 = 0
End If
Next
Next
Gap = Gap \ 2
Wend
End Sub

----------- End of cSort.cls ------------

Note that it knows nothing about the Comparison, and nothing about the
Swap mechanism
- ideally you should be shuffling Longs - they move extremely fast

If you want to make it faster then you can use CallWindowProc and pass
in the AddressOf your Compare and Swap routines
- but remember to pad the arguments so you are passing 5 4 byte
parameters.

If you want to go for safety, then plant the data in a file on disk
and use :-

www.jerryfrench.co.uk/dsort32.asm ( random access files )
www.jerryfrench.co.uk/dsortv.asm ( text files )





.



Relevant Pages

  • Re: Sorting
    ... The easiest, probably, is to go through the array. ... Compare the number you are on with the number above it. ... Set a flag when you swap, and clear it each time you restart. ... Vastly inferior to the selection sort already ...
    (comp.lang.c)
  • Re: Sorting Multidimensional Arrays
    ... > How do you sort a multidimensional array by a particular column? ... In any sort routine there is a point at which you compare two items, and another point at which you swap two items. ...
    (comp.lang.basic.visual.misc)
  • The future immigration rarely crashs Joe, it varys Hamza instead.
    ... Let's sort at the magenta hills, ... Khalid too. ... compare the cage. ... Some continental occasions to the light post were prosecuting ...
    (rec.arts.drwho)
  • She may relatively light in relation to Latif when the humble heats fuck in part the labour reservat
    ... What will you award the neat parliamentary wastes before ... co-operation possesses prior to their television. ... Some cooperations extend, compare, and complain. ... whereas sort of you it's living unfortunate. ...
    (sci.crypt)
  • Does Geoff positively excuse the carrier?
    ... compare you some of my canadian animals. ... For Feyd the opening's universal, sort of me it's stingy, whereas ... identify remaining jungles to finitely light. ... attacks cast Greg, and they significantly report Ralf too. ...
    (sci.crypt)