Marco,
Maybe this old message will help.
James
----------------------------------------
From: "Victor Spiridonov" <dicch@mail.ru>
Subject: Re: Sorting multidimensional array
Date: Wednesday, November 05, 2003 11:06 PM
"Stephen Quinn" <steveqNOSPAM@integritynet.com.au> wrote in message news:<bobukt$1d6h8g$1@ID-88745.news.uni-berlin.de>...
> decray
>
> > I'm trying to sort multidimensional arrays.
> > I have tried with asort(aarray,,,{|x,y| x[1] >y[1]}); but this only
> > change the column order and it doesnt work.
> It does - your just NOT getting the result you want <g>
>
> If you want to sort each dimension then try sorting them individually
>
> Eg - Untested
> for i := 1 to len( aArray )
> aArray1 := aArray[i]
> asort( aArray1,,,{|x,y| x[1] >= y[1] } )
> aArray[i] := aArray1
> next
Decray
Below is the function you are looking for
(in my previous message I've not replace 2 recursive calls to
the new function name and parameters order)
FUNCTION mFaSo2Dim(mAr,mColumn,mL,mR) // fast sorting of two-dimentional array mAr
// mAr - array to be sorted
// mColumn - column array to be sorted on
// mL - index of the first element of area to be sorted
// mR - index of the last element of the area to sort
//Function returns Nil
Local mSrtFlg,mI,mJ,mX,mW,mV,mT
if mL=nil; mL=1; endif
if mR=nil; mR=len(mAr); endif
if mR>1
mSrtFlg=.t.
mI=mL
mJ=mR
mX=mAr[(mL+mR)/2,mColumn]
Do While ((mI<mJ).or.mSrtFlg)`
mSrtFlg = .f.
Do While (mAr[mI,mColumn]<mX)
mI++
EndDo
Do While (mAr[mJ,mColumn]>mX)
mJ--
EndDo
If mI <= mJ
mW = mAr[mI]
mAr[mI] = mAr[mJ]
mAr[mJ] = mW
mI++
mJ--
EndIf
Loop
EndDo
If mL < mJ
mFaSo2Dim(mAr,mColumn,mL,mR)
EndIf
If mR > mI
mFaSo2Dim(mAr,mColumn,mL,mR)
EndIf
Endif
RETURN Nil