In-place merge sort algorithm