initial call to this function is arrange(arr,n/3,n/3) where n is actually
3*n as per the question , like n=30 for a1,...,a10,b1,...,b10,c1,....c10

The idea used here is that for some i-1 ranging from 1 to 9 for above
example, i-1 goes to 3*(i-1), n+i-1 to 3*(i-1) +1, and 2*n+i-1 to
3*(i-1)+2.. recursive function calls are used


void arrange(int arr[], int n, int i)
{

if(i == 1)
{
arr[1] = arr[n];
arr[2] = arr[2*n];
return;
}
int a = arr[i - 1];
int b = arr[n + i - 1];
int c = arr[2*n + i - 1];

arrange(arr, n, i - 1);

int x = 3 * (i - 1);
arr[x] = a;
arr[x + 1] = b;
arr[x + 2] = c;
}



On Sat, Oct 15, 2011 at 11:14 AM, Ankur Garg <ankurga...@gmail.com> wrote:

> @Dan ..can you post the algo here or link to the book??
> @Anika ...yes please post the code here..but please explain a bit about
> underlying algo ...(algo is more important than actual code )
>
>
>
> On Sat, Oct 15, 2011 at 1:54 AM, Dan <dant...@aol.com> wrote:
>
>> On Oct 13, 7:52 pm, "shiva@Algo" <shiv.jays...@gmail.com> wrote:
>> > Convert an array "a1 a2 a3...an b1 b2 b3...bn c1 c2 c3...cn" to "a1b1c1
>> > a2b2c2...anbncn", inplace
>>
>>
>> See the algorithm for memory efficient rearrangement of array elements
>> in one of the books by Robert Sedgewick such as Algorithms in C++ or
>> Algorithms in Pascal, etc.
>>
>> Dan
>>
>> --
>> 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.
>

-- 
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.

Reply via email to