1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| const quickSort1 = (arr) => { const swap = (swapArr, a, b) => { [swapArr[a], swapArr[b]] = [swapArr[b], swapArr[a]]; }
const partition = (partArr, left, right) => { const pivot = partArr[right]; let storeIndex = left; for(let i = left; i < right; i++) { if (partArr[i] < pivot) { swap(partArr, storeIndex, i); storeIndex++ } } swap(partArr, right, storeIndex); return storeIndex; }
const sort = (sortArr, left, right) => { if(left > right) { return } const povit = partition(sortArr, left, right); sort(sortArr, left, povit - 1); sort(sortArr, povit + 1, right); }
sort(arr, 0, arr.length - 1); return arr; };
|