Need a Better Algorithm here is a trivial question we are given an array of 2n elements in the form {a1,a2,a3,......,an,b1,b2,b3b.......bn}
we need to output a resultiing array in the form {a1,b1,a2,b2........,an,bn} but without using another array here is my algorithm which uses nested loops can anyone provide a better solution which doesnt involve shifting. int i,j,k,temp; j=num; int Interleave(int *arr) { for(i=1;i<2*num - 1;i+=2) { temp = arr[j]; for(k=j;k>=i+1;--k) arr[k]=arr[k-1]; arr[i] = temp; ++j; } } -- 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.