Hello,
Im trying to shift my array left as efficiently as possible. Im using pointers now, and im having trouble assigning the values back into my array:
void stack::rotate(int nRotations)
{
if ( count <= 1 ) return;
int *intFrontPtr = &items[top+1].n;
int *intBackPtr = &items[count-1].n;
int temp = 0;
for (int shift = 0; nRotations != 0 ;)
{
if ( nRotations > 0 ) // we rotate left
{
temp = *++intFrontPtr; // give temp the value
items[++shift].n = temp; // debug shows success
if ( shift == count ) // dont overrun array
{
temp = *intBackPtr;
items[count-1].n = temp;
shift = 0; // reset for another rotation
nRotations--; // decrement we have reached the end
}
}
}
}