Cleanup
Optimization: use media of first, middle and last element as the pivot in quicksort.

See Sedgewick1998 (or Wikipedia's article on quicksort).