[algogeeks] program puzzle

2011-08-15 Thread programming love
write a program to reverse the words in a give string. also state the time complexity of the algo. if the string is i am a programmer the output should be programmer a am i -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] program puzzle

2011-08-15 Thread sukran dhawan
reverse(string,n) // do it in place p = str; for(i=0;ilength(str);i++) { if(str[i] == '\0' || str[i] == ' ') { reverse(p,len); p = p+len+1; len = 0; } else len++; } On Mon, Aug 15, 2011 at 4:48 PM, programming love love.for.programm...@gmail.com wrote:

Re: [algogeeks] program puzzle

2011-08-15 Thread MeHdi KaZemI
string str = i am a programmer for(int i = 0; i str.size()/2; i ++) swap(str[i], str[str.size()-i-1]); time complexity O(n) On Mon, Aug 15, 2011 at 6:39 PM, sukran dhawan sukrandha...@gmail.comwrote: reverse(string,n) // do it in place p = str; for(i=0;ilength(str);i++) {

Re: [algogeeks] program puzzle

2011-08-15 Thread Dipankar Patro
@ MeHdi : Please read the problem properly yaar. You are just reversing the string by characters, not by words. On 15 August 2011 20:34, MeHdi KaZemI mehdi.kaze...@gmail.com wrote: string str = i am a programmer for(int i = 0; i str.size()/2; i ++) swap(str[i], str[str.size()-i-1]);

Re: [algogeeks] program puzzle

2011-08-15 Thread siddharth srivastava
On 15 August 2011 16:48, programming love love.for.programm...@gmail.comwrote: write a program to reverse the words in a give string. also state the time complexity of the algo. It has already been discussed on the list a few days ago if the string is i am a programmer the output should

Re: [algogeeks] program puzzle

2011-08-15 Thread *$*
method 1: algo: step 1 :reverse entire string .. (letter by letter) step 2: take two pointers ... keep first pointer at the starting of the word ... keep incrementing the second pointer , till space hits.. then , swap first pointer and second pointere data , by incrementing first pointer , and

Re: [algogeeks] program puzzle

2011-08-15 Thread priya ramesh
@gopi: Each word is being accessed thrice. 1. reverse string 2. set pointers to beginning n end of string 3. reverse the word. If this is the came is the complexity O(n)?? It's a very good algo nevertheless :) On Mon, Aug 15, 2011 at 9:16 PM, *$* gopi.komand...@gmail.com wrote: method 1:

Re: [algogeeks] program puzzle

2011-08-15 Thread Anil Arya
First reverse the senetence word by word and then reverse the whole stringthat will be easier On Mon, Aug 15, 2011 at 4:48 PM, programming love love.for.programm...@gmail.com wrote: write a program to reverse the words in a give string. also state the time complexity of the algo. if

Re: [algogeeks] program puzzle

2011-08-15 Thread Anil Arya
http://geeksforgeeks.org/?p=7150 that will clear you very well.i'm sure... On Mon, Aug 15, 2011 at 4:48 PM, programming love love.for.programm...@gmail.com wrote: write a program to reverse the words in a give string. also state the time complexity of the algo. if the string is i am a