This is one way of doing it without index.
> #include <stdio.h> > #include <string.h> > > void reverse(char *begin, char *end) > { > char temp; > > while ( begin <= end ) > { > temp = *begin; > *begin = *end; > *end = temp; > begin++; > end--; > } > } > > int main() > { > char str[100]; > > scanf ("%s", str); > > reverse(str, str + strlen(str) - 1); > > printf ("Reversed String = %s\n", str); > > return 0; > } > > > On Tue, May 31, 2011 at 12:14 PM, Supraja Jayakumar < suprajasank...@gmail.com> wrote: > 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<stdio.h> > #include<string.h> > > void reverse(char s[]) { > > int len = sizeof(s)/sizeof(char); > printf("%d\n", len); > if(len == 1 || len == 0) > return; > int i,j; > for(i = 0, j = len-1; i < len, j >= 0; i++, j--) { > if(i >=j) > break; > char temp = s[i]; > s[i] = s[j]; > s[j] = temp; > printf("%c%c\n", s[i], s[j]); > } > } > > int main() { > char s[7] = {'a','b','x','c', 'l', 'm', 'y'}; > reverse(s); > int i; > for(i = 0; i < 7; i++) > printf("%c", s[i]); > return 0; > > } > > > On Tue, May 31, 2011 at 12:04 PM, nagajyothi gunti < > nagajyothi.gu...@gmail.com> wrote: > >> 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; >> int j=0; >> for(int i=0;i<mid;i++){ >> j = str.Length-1-i; >> temp = char_str[i]; >> char_str[i] = char_str[j]; >> char_str[j] = temp; >> } >> >> Console.Write(char_str.ToString()); >> >> Console.Read(); >> >> } >> } >> >> On Sat, May 28, 2011 at 7:53 AM, <adityasir...@gmail.com> wrote: >> >>> 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<name.length();i++){ >>> >>> System.out.println(name.charAt(i) + reverse); >>> reverse = name.charAt(i) + reverse; >>> } >>> } >>> } >>> >>> >>> On Sat, May 28, 2011 at 6:40 AM, abc abc <may.i.answ...@gmail.com>wrote: >>> >>>> *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 unsubscribe from this group, send email to >>>> algogeeks+unsubscr...@googlegroups.com. >>>> For more options, visit this group at >>>> http://groups.google.com/group/algogeeks?hl=en. >>>> >>> >>> -- >>> 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 >>> algogeeks+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> >> >> -- >> Jyothi >> >> -- >> 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 >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > U > > -- > 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 > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- -Aakash Johari (IIIT Allahabad) -- 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 algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.