You are viewing a single comment's thread. Return to all comments →
The question asks to shift a fully formed array, not to shift elements to their position as they're read in. Start with a fully formed array, then this solution does not work.
thats what me too thinking of..was wondering why the logic writte here was arranging the array on read...
That's exactly the point of the exercise. You have to rotate an already existing array.
I noticed that right away. If the point was to produce printed output, then this is fine (and a lot of analysis works backward from output). But, as stated, one is supposed to shift an array, so this missed it.
this could easily be modified though by creating another array of the same size:
for(int i = 0; i < n; i++)
b[i] = a[(i+k) % n];