Are there any constraints in the problem, because it seems straight forward.
if number of elements are 2n indexed from 0 to 2n-1 for i=0 to n-1: new_array[i*2]=old_array[i]; new_array[i*2+1]=old_array[i+n]; On Mon, Feb 28, 2011 at 7:41 PM, bittu <shashank7andr...@gmail.com> wrote: > @jalaj U needs to clarify becoz what i can say that dat is overwritten > in ur explanation so we loosing the original data where we are saving > when we swapping the elements ur explanation seems to be right but > little confusing > > @ujjwal i haven't tested ur code but i think its O(n^2) then why not > try for this 20 Line Simple code of O(n^2) > > Finally we wants O(n) better solution fro this which exist for > this ??? > > #include<string.h> > > void swap(char *c,char *p) > { > char tmp; > tmp=*c; > *c=*p; > *p=tmp; > > } > > int main (int argc, char const* argv[]) > { > char str[] = "1234abcd"; > int i,j; > int len = strlen(str)/2; > //swap str[len-1] and str[len] and so on > for ( i = 0; i < len-1; i += 1) { > for ( j = len-1-i; j <= len+i; j += 2) > { > printf("i=%d j=%d c1=%c \t c2=%c > \n",i,j,str[j],str[j+1]); > swap(&str[j],&str[j+1]); > } > } > printf("%s \n", str); > return 0; > } > > Time Complexcity O(n^2) O(n) Needed..???? > > > Thanks & Regards > Shashank >> "The Best Way to escape From The Problem is Solve It" > > -- > 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.