You have basically 2 techniques
- Rotation with copy to a new list
- Rotation in place
Rotation with copy is the technique of solution 1.
To calc to new positionof an element, you have to apply the formula:
NewPosition= (OldPosition+ Rotation) % SizeOfList
Rotation in place
Only rotation of 1 and -1 are practical. You just have to repeat as many times as needed.
- pseudo code
if (rotation== -1)
{
tmp= list[0]
for scan= 1; scan < list.count; scan++)
{
list[scan-1]= list[scan];
}
list[list.count-1]= tmp;
}
else
{
tmp= list[list.count-1]
for scan= list.count-1; scan >=0; scan--)
{
list[scan]= list[scan-1];
}
list[0]= tmp;
}