MCPcopy Create free account
hub / github.com/careercup/CtCI-6th-Edition-JavaScript / partition

Function partition

chapter10/sortingAlgos/quickSort.js:10–29  ·  view source on GitHub ↗
(array, left, right)

Source from the content-addressed store, hash-verified

8};
9
10const partition = (array, left, right) => {
11 const pivotIndex = Math.floor((left + right) / 2);
12 const pivot = array[pivotIndex];
13 while(left <= right) {
14 while(array[left] < pivot) {
15 left++;
16 }
17 while(pivot < array[right]) {
18 right--;
19 }
20 if (left <= right) {
21 console.log(`swap ${array[left]} and ${array[right]}`);
22 swap(array, left, right);
23 console.log(array);
24 left++;
25 right--;
26 }
27 }
28 return left;
29};
30
31const quickSort = (array, left, right) => {
32 const index = partition(array, left, right);

Callers 1

quickSortFunction · 0.70

Calls 1

swapFunction · 0.70

Tested by

no test coverage detected