Re: [algogeeks] Re: Reversing a string

2011-06-02 Thread snehi jain
recursive version of the code void rev(char *beg, char *end) { if(beg<=end) rev(beg+1, end-1); else return ; swap(beg,end); } On Wed, Jun 1, 2011 at 5:46 PM, saurabh singh wrote: > > Tho a do while loop in place of the second while loop will do

Re: [algogeeks] Re: Reversing a string

2011-06-01 Thread saurabh singh
Tho a do while loop in place of the second while loop will do equally good. On Wed, Jun 1, 2011 at 5:45 PM, saurabh singh wrote: > > Ya thanks. > > On Wed, Jun 1, 2011 at 5:35 PM, rohit wrote: > >> @saurabh singh >> one lil addition make your code complete. >> >> #include >> #include >> >> i

Re: [algogeeks] Re: Reversing a string

2011-06-01 Thread saurabh singh
Ya thanks. On Wed, Jun 1, 2011 at 5:35 PM, rohit wrote: > @saurabh singh > one lil addition make your code complete. > > #include > #include > > int main() >{ >char s[20],t[30],*p,*q; >scanf("%s",s); >p=s; >q=t; >while(*(++p)!='\0'); >p--; >while(p!=s) >

[algogeeks] Re: Reversing a string

2011-06-01 Thread rohit
@saurabh singh one lil addition make your code complete. #include #include int main() { char s[20],t[30],*p,*q; scanf("%s",s); p=s; q=t; while(*(++p)!='\0'); p--; while(p!=s) { *(q++)=*(p--); } *(q++)=*(p--);// first character of str

[algogeeks] Re: Reversing a string

2011-06-01 Thread Maksym Melnychok
without indexes in erlang: reverse(String) -> reverse(String, []). reverse([], NewString) -> NewString; reverse([Head|Rest], NewString) -> reverse(Rest, [Head|NewString]). -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this d

[algogeeks] Re: Reversing a string !!

2007-10-31 Thread Somesh Jaiswal
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(str)/2;i++;j--) swap(str[i],str[j]); } On 10/31/07, Some

[algogeeks] Re: Reversing a string !!

2007-10-31 Thread Somesh Jaiswal
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 cons

[algogeeks] Re: Reversing a string !!

2007-10-31 Thread hongcheng zhu
Reverse the whole string first. Then reverse every word. 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 aweso

[algogeeks] Re: Reversing a string !!

2007-10-30 Thread Sumedh Sakdeo
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 word