[algogeeks] Re: reverse a string efficiently

2012-11-27 Thread Don
Reversing a string should be linear time. void reverse(char *str) { int i = 0; int j = strlen(str)-1; while(i j) swap(str[i++], str[--j]); } On Nov 27, 12:47 am, shady sinv...@gmail.com wrote: what is the time complexity of this? str_reverse(str){     if(isempty(str)) return

Re: [algogeeks] Re: reverse a string efficiently

2012-11-27 Thread Vineeth
i guess it should be swap(str[i++], str[j--]); because we already subtracted 1 On Tue, Nov 27, 2012 at 8:58 PM, Don dondod...@gmail.com wrote: swap(str[i++], str[--j]); --