Optimal in-place sorting of vectors and records