Fix a bug in qsort

Try `qsort [3,3]`. Under the old code, you'd get `[3,3,3]` out.
Merge pull request #1406 from jthemphill/fix-qsort

Fix a bug in qsort