Zhu's solution is perfect.
I've written a code for it. Kindly revert if any flaw is there.
Pl take multiple spaces in account.

main()
{
int start=0;end=0;
char *string = "My name is somesh";
reverse(string, 0, 15);
for(int i=0; i<strlen(string); i++)
    {
    if(string[i] == " " || string[i] == "\t")
        {
        end = i-1;
        reverse(string,start,end);
        start = i;
        }
    }
}

void reverse(char *str, int start, int end)
{
if(end == start || end < start)
    return;
length = (end - start) -1;
for(i=0;j=strlen(str)-1;i<strlen(str)/2 && j>=strlen(str)/2;i++;j--)
    swap(str[i],str[j]);
}

On 10/31/07, Somesh Jaiswal <[EMAIL PROTECTED]> wrote:
>
> But still the constraint will be the length of string member per node.
> To make it dynamic we'll have to add each node a linked list having the
> words.
>
> On 10/31/07, Sumedh Sakdeo <[EMAIL PROTECTED]> wrote:
> >
> > store the words in linked list while taking the input... As they have
> > not mentioned constraints on data structure ..
> > and reverse the linked list...
> > Regards,
> > Sumedh
> >
> > On 10/31/07, Somesh Jaiswal < [EMAIL PROTECTED]> wrote:
> > >
> > > Hi,
> > >
> > > I was asked a question in an interview to Reverse the order of words
> > > in a sentence.
> > > eg. "Google is an awesome place to work"  should be reversed as "work
> > > to place awesome an is Google"
> > > The solution should be efficient and shouldn't use any extra memory.
> > >
> > > Pl suggest me some solution.
> > >
> > > Regards,
> > > Somesh
> > >
> > >
> > >
> > >
> >
> > > >
> >
>
>
> --
> Somesh Jaiswal




-- 
Somesh Jaiswal

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to