Fog Creek Software
Discussion Board

Reverse String

This can easily be achieved by making use of a stack. e.g "The sky is blue". Each word delimited by a space can be pushed onto a stack that accepts a string object and then popped to return the string "blue is sky the"

Gautam Bajekal
Friday, April 11, 2003

Ah, but the challenge is to reverse the string word by word *in place,* which you can take to mean having constant memory usage.

Peter Meilstrup
Friday, April 11, 2003

simple solution is:
first reverse the whole string, and then reverse all the words.

original : the sky is blue
step1 :  eulb si yks eht
step2 : blue is sky the

that's it .
so, there is no memory wastage

Monday, April 14, 2003

*  Recent Topics

*  Fog Creek Home