Complete efficient quicksort algorithm