function quickSort(array) { function swap(array, i, k) { var temp = array[i]; array[i] = array[k]; array[k] = temp; } function partition(array, left, right) { var storeIndex = left; var pivot = array[right]; for (var i = left; i < right; i++) { if (array[i] < pivot) { swap(array, storeIndex, i); storeIndex++; } } swap(array, right, storeIndex); return storeIndex; } function sort(array, left, right) { if (left > right) { return; } var storeIndex = partition(array, left, right); sort(array, left, storeIndex - 1); sort(array, storeIndex + 1, right); } sort(array, 0, array.length - 1); return array; } quickSort([9, 1, 5, 8, 3, 7, 4, 6, 2])
|