Rearrange array from a0,a1,a2,..,an,b0,b1,b2,..,bn to a0,b0,a1,b1,...an,bn without extra space
I am trying to solve this by using below code in c# - this is resolving the first half but not the second half.
Any help would be appreciated.
public void RearrangeArray(ArrayList a, int p, int q)
{
if (p == q)
return;
int r = (p + q) / 2;
int s = (q + r) / 2;
int fmid = (p + r) / 2;
int shp = r + 1;
object temp;
for (int i = fmid + 1; i <= r; i++)
{
temp = a[i];
a[i] = a[shp];
a[shp++] = temp;
}
RearrangeArray(a, p, r);
RearrangeArray(a, r + 1, q);
}
```