Re: non-recursive quicksort for 2-D arrays?
- From: "RB Smissaert" <bartsmissaert@xxxxxxxxxxxxxxxx>
- Date: Sun, 7 May 2006 20:07:41 +0100
OK, now I got you.
You are saying don't use a quicksort as it causes stack problems, but use a Shell Sort, which doesn't
but is nearly as quick.
Actually, I have rarely come across situation where the quicksort didn't work with an error message:
out of stack space.
This was with very large arrays.
I solved this in a way that is most likely completely inefficient, namely run the quicksort on increasingly
bigger parts of the array, but always including LBound.
This is the code:
Function PreSort2DVar(ByRef vArray As Variant, _
ByRef lKey As Long, _
Optional ByRef bAscending As Boolean = True, _
Optional ByRef lLow1 As Long = -1, _
Optional ByRef lHigh1 As Long = -1) As Boolean
'the routine procSort2D can't handle large arrays
'causing an error out of stack space
'this is handled by sorting increasing larger parts
'of the array, so that there is less to be done when
'the whole array gets sorted
'---------------------------------------------------
Dim LR As Long
Dim lPreSorts As Long
Dim lArrayChunk As Long
Dim n As Long
LR = UBound(vArray)
'this value may depend on the hardware
'-------------------------------------
lArrayChunk = 8000
'no need to do pre-sorts
'-----------------------
If LR < lArrayChunk Then
PreSort2DVar = Sort2DVar(vArray, _
lKey, _
bAscending, _
lLow1, _
lHigh1)
Exit Function
End If
lPreSorts = LR \ lArrayChunk
For n = 0 To lPreSorts
If n < lPreSorts Then
'increase the part of the array in steps of lArrayChunk
'------------------------------------------------------
PreSort2DVar = Sort2DVar(vArray, _
lKey, _
bAscending, _
lLow1, _
(n + 1) * lArrayChunk)
Else
'sort the whole array
'--------------------
PreSort2DVar = Sort2DVar(vArray, _
lKey, _
bAscending, _
lLow1, _
lHigh1)
End If
Next
End Function
Where Sort2DVar is a regular quicksort.
Now this is probably crap, although as I say it solves the out of stack problem.
Will have a look at the Shell Sort and see how it performs.
RBS
"J French" <erewhon@xxxxxxxxxx> wrote in message news:445e3973.35789591@xxxxxxxxxxxxxxxxxxxxxxx
On Sun, 7 May 2006 17:23:54 +0100, "RB Smissaert"
<bartsmissaert@xxxxxxxxxxxxxxxx> wrote:
OK, thanks.
What though is the essence of your reply?
Did you think you have code that works faster?
Now I don't know why you were fossicking around finding the mid point
That is not me, I just copied a standard quicksort. I don't think I can
improve on that.
Do not copy anything
- take it, understand it anf /own/ it
What is slightly confusing is that you are talking about pointers and ptr,
but you not dealing
with real pointers (memory addresses) but it looks you mean array indices,
that is array row
numbers.
Stuff memory addresses - one day you will learn that they are not real
(they used to be)
What is the idea of calling that variable L9, I mean what does the 9 stand
for?
Outer most Loop - drummed into me years ago
- if you see another coder using the same convention then ask for a
few more
I also don't follow the ascending/descending stuff
Not sure what the problem is there. Don't I need an argument in my function
to tell if we
are sorting descending or ascending? What is wrong with the way that is done
now, which is just
the standard quicksort in any case.
My rules are very simple
1) Quicksort is crap - it is parasitic on the stack
- it will hit you when you least expect it
2) Simplify
3) Ascending or Descending is just the way you look at things
.
- 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
- Re: non-recursive quicksort for 2-D arrays?
- From: J French
- Re: non-recursive quicksort for 2-D arrays?
- From: Ulrich Korndoerfer
- Re: non-recursive quicksort for 2-D arrays?
- From: J French
- Re: non-recursive quicksort for 2-D arrays?
- From: Ulrich Korndoerfer
- Re: non-recursive quicksort for 2-D arrays?
- From: Jim Mack
- Re: non-recursive quicksort for 2-D arrays?
- From: Ulrich Korndoerfer
- Re: non-recursive quicksort for 2-D arrays?
- From: RB Smissaert
- Re: non-recursive quicksort for 2-D arrays?
- From: J French
- Re: non-recursive quicksort for 2-D arrays?
- From: RB Smissaert
- Re: non-recursive quicksort for 2-D arrays?
- From: J French
- Re: non-recursive quicksort for 2-D arrays?
- From: RB Smissaert
- Re: non-recursive quicksort for 2-D arrays?
- From: J French
- non-recursive quicksort for 2-D arrays?
- Prev by Date: Re: Open a file into a VB6 TextBox
- Next by Date: Re: Run a DOS program form my VB program?
- 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
|