In many languages, the basic version can be just one line of code, if you know the right libraries to leverage. C# leveraging Linq, for example:
String.Join(" ", String.Split(" ", sentence).Reverse()))