Return to Snippet

Revision: 423
at July 13, 2006 00:32 by sergiomas


Initial Code
function quickSort(arrayInput, left, right) {

i = left;
j = right;
pivotPoint = arrayInput[Math.round((left+right)*.5)];
// Loop
while (i<=j) {

while (arrayInput[i]<pivotPoint) {

i++;

}
while (arrayInput[j]>pivotPoint) {

j--;

}
if (i<=j) {

tempStore = arrayInput[i];
arrayInput[i] = arrayInput[j];
i++;
arrayInput[j] = tempStore;
j--;

}

}
// Swap
if (left<j) {

quickSort(arrayInput, left, j);

}
if (i<right) {

quickSort(arrayInput, i, right);

}
return;

}

Initial URL
http://www.kirupa.com/developer/actionscript/quickSort.htm

Initial Description
Ejemplo de uso:

//
// Example
//
arrayInput = [6358, 6850, 1534, 3928, 9766, 3822, 1025, 7616, 106, 117, 1569, 2882, 1627, 726, 429, 2234, 7804, 7562, 3640, 1905, 3458, 3242, 2270, 251, 23, 6358, 7719, 2762, 2507, 3335, 1947, 7535, 6249, 4139, 5012, 6792, 2967, 3254, 1823, 1653, 8856, 2278, 3309, 7754, 1267, 9631, 9300, 5431, 764, 4452, 5842, 9347, 8269, 1037, 257, 9299, 2282, 5002, 449, 3533, 1120, 926, 1270, 8210, 4453, 5849, 7275, 2985, 1825, 4173, 5948, 8364, 2651, 6105, 7632, 1334, 494, 7669, 3816, 6339, 5693, 1410, 7496, 6238, 1848, 9332, 8707, 6575, 2810, 2267, 5913, 9436, 4778, 472, 1823, 1972, 105, 889, 3421, 7885, 5221, 2982, 2808, 9737, 3318, 9093, 8105, 6787, 2880, 3779, 4118, 1783, 5397, 5928, 5534, 3744, 2054, 1237, 9087, 3638, 8523, 3062, 6820, 7450, 6153, 2789, 3564, 3289, 5246, 9834];
quickSort(arrayInput, 0, arrayInput.length-1);
trace(arrayInput);

Initial Title
Ordenar un array

Initial Tags


Initial Language
ActionScript