How to rotate an integer array by i times using swap function only in linear time.
Using linear time O(2N+m), and constant space O(4). m = GCD(n, p)
It's up to 50% faster than the swapping approach, because swapping requires writing O(N) times to a temporary.
http://www.eis.mdx.ac.uk/staffpages/r_bornat/oldteaching/I2A/slides%209%20circshift.pdf
for (m=0, count=0; count!=n; m++) {
type t=A[m];
for (i=m, j=m+p; j!=m; i=j, j = j+p