Skip to content

Commit 5d08eec

Browse files
committed
Implement quick sort
1 parent 6a993dc commit 5d08eec

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Sorting/QuickSort.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,13 @@ function pivot(arr, comparator, start = 0, end = arr.length - 1) {
8484
pivotIndex = swapIndex - 1;
8585
return pivotIndex;
8686
}
87+
88+
function quickSort(arr, comparator, start = 0, end = arr.length - 1) {
89+
if (start > end) return [];
90+
91+
const pivotIndex = pivot(arr, comparator, start, end);
92+
quickSort(arr, comparator, start, pivotIndex - 1);
93+
quickSort(arr, comparator, pivotIndex + 1, end);
94+
95+
return arr;
96+
}

0 commit comments

Comments
 (0)