Skip to content

Commit c84c42c

Browse files
committed
Fixed quicksort
1 parent 3d611c1 commit c84c42c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

algorithms/sorting/quicksort/quicksort.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function swap(items, firstIndex, secondIndex){
3636

3737
function partition(items, left, right) {
3838

39-
var pivot = items[Math.ceil((right + left) / 2)], // pivot value is middle item
39+
var pivot = items[Math.floor((right + left) / 2)], // pivot value is middle item
4040
i = left, // starts from left and goes right to pivot index
4141
j = right; // starts from right and goes left to pivot index
4242

@@ -94,7 +94,7 @@ function quickSort(items, left, right) {
9494
}
9595

9696
if (index < right) {
97-
quickSort(items, index + 1, right);
97+
quickSort(items, index, right);
9898
}
9999

100100
}

0 commit comments

Comments
 (0)