implement qsort in-place