## Posted By

sergiomas on 07/13/06

# Ordenar un array

/ Published in: ActionScript

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);

1. function quickSort(arrayInput, left, right) {
2.
3. i = left;
4. j = right;
5. pivotPoint = arrayInput[Math.round((left+right)*.5)];
6. // Loop
7. while (i<=j) {
8.
9. while (arrayInput[i]<pivotPoint) {
10.
11. i++;
12.
13. }
14. while (arrayInput[j]>pivotPoint) {
15.
16. j--;
17.
18. }
19. if (i<=j) {
20.
21. tempStore = arrayInput[i];
22. arrayInput[i] = arrayInput[j];
23. i++;
24. arrayInput[j] = tempStore;
25. j--;
26.
27. }
28.
29. }
30. // Swap
31. if (left<j) {
32.
33. quickSort(arrayInput, left, j);
34.
35. }
36. if (i<right) {
37.
38. quickSort(arrayInput, i, right);
39.
40. }
41. return;
42.
43. }