Skip to content

Commit 62cb0c4

Browse files
committed
Use overflow-safe midpoint in quick sort pivot
1 parent 61eb8f7 commit 62cb0c4

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/lib/sort-algorithms/quick-sort.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { SortingGenerator } from './types';
22

33
function* partition(items: number[], left: number, right: number) {
4-
const pivot = items[Math.floor((right + left) / 2)]; // 1 read
4+
const pivot = items[left + Math.floor((right - left) / 2)]; // 1 read
55
let i = left;
66
let j = right;
77
while (i <= j) {

0 commit comments

Comments
 (0)