Finished universal algorithm for first, last and median pivot