Quick sort with median pivot