By
gononono64
Hey there,
I'm having some issues quick-sorting my 2d array imported from a database. Im trying to sort the array based on the name that would be returned in $array[$n][2]. The code i posted works for smaller arrays but for some reason when i try to sort my imported array (around 9000 indexes), I get "Recursion level has been exceeded". I understand that this is maybe due to lack of returns but i couldn't find an ideal spot to stick em and again it seems to work with smaller bits of code. Could it be that 9000 is too much?
I would normally just trial and error it until i figured it out but due to the length of time to load and buffer my array it's become too time consuming. Really I'm just hoping there is a quick fix that someone with more experience happens to know.
Thank you
;;---------------------------------------------This Works----------------------------------------------------
Local $a[7][2] = [ _
["1", "asdfashks"], _
["2", "SubStrlkghjing1"], _
["3", "jdfghjsergh"], _
["4", "nertynert"], _
["5", "cvbncvjkrt"], _
["6", "avbncvjkrt"], _
["7", "oytuoyuop"]]
Quicksort($a,1,0,6)
_ArrayDisplay($a)
;;------------------------------------------This Does Not---------------------------------------------------------
Quicksort($aLargeData, 1, 0, Ubound($aLargeData) - 1)
_ArrayDisplay($aLargeData)
;;----------------------------------------Quicksort Function------------------------------------------------------
Func Quicksort(ByRef $Array, $secondIndex, $First, $Last)
Local $pivot, $i, $j, $temp
If $First < $Last Then
$pivot = $First
$i = $First
$j = $Last
While ($i < $j)
While (StringCompare($Array[$i][$secondIndex], $Array[$pivot][$secondIndex]) <= 0) And ($i < $Last)
$i += 1
WEnd
While (StringCompare($Array[$j][$secondIndex], $Array[$pivot][$secondIndex]) > 0)
$j -= 1
WEnd
If ($i < $j) Then _ArraySwap($Array, $i, $j)
_ArraySwap($Array,$pivot,$j)
Quicksort($Array, $secondIndex, $First,$j-1)
Quicksort($Array, $secondIndex, $j+1,$Last)
WEnd
EndIf
EndFunc