We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 631d586 + 7c01b95 commit 2e8b6d1Copy full SHA for 2e8b6d1
quickSort.js
@@ -0,0 +1,17 @@
1
+function partition(arr, start, end){
2
+ // Taking the last element as the pivot
3
+ const pivotValue = arr[end];
4
+ let pivotIndex = start;
5
+ for (let i = start; i < end; i++) {
6
+ if (arr[i] < pivotValue) {
7
+ // Swapping elements
8
+ [arr[i], arr[pivotIndex]] = [arr[pivotIndex], arr[i]];
9
+ // Moving to next element
10
+ pivotIndex++;
11
+ }
12
13
+
14
+ // Putting the pivot value in the middle
15
+ [arr[pivotIndex], arr[end]] = [arr[end], arr[pivotIndex]]
16
+ return pivotIndex;
17
+};
0 commit comments