elegant way of reversing words in a sentence and an inplace sort