I have a homework assignment that requires having to shift a circular array -n places in memory.
I have accomplished the task with the following C++ Syntax:
while ( r < 0 ) // rotate negatively.
{
if ( i == top+1 )
{
current->n = items[top+1].n;
items[top+1].n = items[back-1].n;
}
midPtr->n = items[++i].n;
items[i].n = current->n;
if ( i == back-1 )
{
items[back-1].n = current->n;
i = 0;
r++; continue;
}
else
{
current->n = items[++i].n;
items[i].n = midPtr->n;
if ( i == back-1 )
{
i = 0;
r++; continue;
}
}
}
I was wondering if anyone has a better, more efficient method of shifting a circular array by -n units.
Because I seem to be performing unnecessary transfers between ptr variables.