Implement arbitrary order in qsort