Hello,
Without using any stls, boosts, and the like I have been trying to rotate the elements in my array. I've been trying to use the mod operator, to be efficient:
void stack::rotate(int r)
{
r = ( r % maxSize + maxSize ) % maxSize;
for ( int first_index = 0; first_index < r; ++first_index )
{
int mem = items[first_index].n;
int index = ( first_index + r ) % maxSize, index_prev = first_index;
while ( index != first_index )
{
items[index_prev] = items[index];
index_prev = index;
index = ( index + r ) % maxSize;
}
items[index_prev].n = mem;
}
Where items is an allocated array to an item struct. Although it is a little weird the item struct has an integer 'n' member so that i may use it with integer type varaibles.
But its still not comming out right =( . Im losing the contents of my second element. I think its break time ;)