Re: [algogeeks] Reversing a string

2011-05-31 Thread Aakash Johari
This is one way of doing it without index. > #include > #include > > void reverse(char *begin, char *end) > { > char temp; > > while ( begin <= end ) > { > temp = *begin; > *begin = *end; > *end = temp; > begin++; > end--; > } > } > > int

Re: [algogeeks] Reversing a string

2011-05-31 Thread Supraja Jayakumar
Hi Pls see below. This is only with indexing. I am not sure how to do it w/o indexing if its not a C-style string or w/o pointer arithmetic. Pls let me know if there is such a technique. I would be very eager to know. Thanks. #include #include void reverse(char s[]) { int len = sizeof(s)/sizeo

Re: [algogeeks] Reversing a string

2011-05-31 Thread nagajyothi gunti
Hope this logic looks better. class Program { static void Main(string[] args) { string str = "string"; char[] char_str=str.ToCharArray(); char temp; int string_length = char_str.Length; int mid = string_length / 2;

Re: [algogeeks] Reversing a string

2011-05-28 Thread adityasirohi
In java you can do this, take O(n) time. Is that correct? -Adi public class ReverseString { public static void main(String[] args){ String name = "Aditya"; String reverse = ""; for(int i=0;i wrote: > *Given an array of characters. How would you reverse it. ? How would you > reverse it without

Re: [algogeeks] Reversing a string

2011-05-28 Thread saurabh singh
#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='\0'; } Is this what you are looking for? I think an inplace solution is required? On Sat, May 28, 2011

[algogeeks] Reversing a string

2011-05-28 Thread abc abc
*Given an array of characters. How would you reverse it. ? How would you reverse it without using indexing in the array.* * * -- 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

[algogeeks] Reversing a string !!

2007-10-30 Thread Somesh Jaiswal
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,