Sunday, July 10, 2011

Reverse the Words in a String in Place

Problem: Reverse the order of words in a string. For example, given "I like Juventus", "Juventus like I" should be the output.

Solution: First in place reverse the whole string. We will get "suntevuJ ekil I". The we just reverse the characters in each word.

No comments:

Post a Comment