3 ms·
Add the following right above the line "pivot = left" to fix it: VA.swap(left, Math.floor(Math.random() * (right - left + 1)) + left)
by sirclueless 15y ago
Add the following right above the line "pivot = left" to fix it:
VA.swap(left, Math.floor(Math.random() * (right - left + 1)) + left)
- CountHackulus 15y agoAlternatively you can insert this code for the median of 3 version: centre = (left + right) / 2; if VA.lt(left, centre) if VA.lt(centre, right) VA.swap(left, centre) else if VA.lt(left, right) VA.swap(left, right) else if VA.lt(centre, right) VA.swap(left, centre) else if VA.lt(left, right) VA.swap(left, right)