1
0
mirror of https://github.com/janet-lang/janet synced 2025-07-06 20:12:53 +00:00
Felix Riedel 3e742ffc4c Improve quicksort to avoid worst case performance.
The current implementation will have quadratic behaviour for already
sorted arrays because it picks the last element as pivot. In an sorted
array this splits the array repeatedly into the biggest value and all
other values.

The implementation in this commit uses the *median of three* as pivot.

`janet -e "(sort (range 10000))"` to reproduce quadratic behaviour.
2020-12-26 19:18:17 +00:00
..
2020-01-12 10:50:37 -06:00
2020-01-12 10:50:37 -06:00
2020-01-12 10:50:37 -06:00