Re: non-recursive quicksort for 2-D arrays?
- From: erewhon@xxxxxxxxxx (J French)
- Date: Fri, 05 May 2006 12:31:15 GMT
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 youshould 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 )
.
- Follow-Ups:
- Re: non-recursive quicksort for 2-D arrays?
- From: Ulrich Korndoerfer
- Re: non-recursive quicksort for 2-D arrays?
- From: bart . smissaert
- Re: non-recursive quicksort for 2-D arrays?
- References:
- non-recursive quicksort for 2-D arrays?
- From: RB Smissaert
- Re: non-recursive quicksort for 2-D arrays?
- From: Mike Williams
- Re: non-recursive quicksort for 2-D arrays?
- From: bart . smissaert
- non-recursive quicksort for 2-D arrays?
- Prev by Date: Re: browser and vb script
- Next by Date: MS-DOS ActiveX Control in VB 6 ?
- Previous by thread: Re: non-recursive quicksort for 2-D arrays?
- Next by thread: Re: non-recursive quicksort for 2-D arrays?
- Index(es):
Relevant Pages
|