Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quick sort manual tail-call optimization
Before, sorting `evil.txt` would have a massive 9,000+ stack size. Now it has a stack size of only 30 or so. We do this by, rather than making two recursive calls to quick sort, we only do a recursive call on the smaller half. For the larger half, we replace the left and right values in the current call and loop. This way, if a poor choice of pivot is made and, for example, we partition a block of size N into pieces 1 and N-2, we don't create a new stack entry for N-2, but instead reuse the current one. Fixes #62 This also fixes a unary minus on an unsigned integer, which creates problems for some compilers (notably MSVC).
- Loading branch information