/**
* @param myArray, sortIndex, left, right
*
* @usage where myArray is the 2d array you want to sort, sortIndex is
* the index of the second array on which you wish to sort,
* left is the lower bound of myArray and right is the upper
* bound of myArray
*
*/
function quickSort(myArray : Array, sortIndex : Number, left : Number, right
: Number) : Array
{
var arrayLen : Number = myArray.length;
var lHold : Number = left;
var rHold : Number = right;
var pivot : Number = myArray[left][sortIndex];
while(left < right)
{
while( (myArray[right][1] >= pivot) && (left < right) )
right--;
if(left != right)
{
myArray[left][sortIndex] = myArray[right][sortIndex];
left++;
}
while( (myArray[left][sortIndex] <= pivot) && (left < right)
left++;
if(left != right)
{
myArray[right][sortIndex] = myArray[left][sortIndex];
right--;
}
}
myArray[left][sortIndex] = pivot;
pivot = left;
left = lHold;
right = rHold;
if( left < pivot)
{
qSort(myArray, sortIndex, left, pivot - 1);
}
if( right > pivot)
{
qSort(myArray, sortIndex, pivot + 1, right);
}
return myArray;
}
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <flashcoders@chattyfig.figleaf.com>
Sent: Thursday, February 01, 2007 11:08 AM
Subject: [Flashcoders] sort 2d array
Hello,
Can anybody tell me how to sort the following array based upon the second
value
within each array item
myArray:Array = [ [20,40],[20,10],[30,15],[30,35],[40,100],[1000,1]];
this should be something like
[[1000,1], [20,10], .....
Faster the better cos its for a game and gets called a lot of times.
regards
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com