C, :
, , .
int stringRotate(int value)
{
unsigned long I,J,K;
unsigned long index0;
unsigned long temp1,temp2;
unsigned long length;
length = stringLength;
if (value < 0)
value = length - ((0 - value) % length);
if (value > length)
value = value % length;
J = 0;
index0 = J;
temp1 = stringData[J];
for (I = 0;I < length;I++)
{
K = (J + value) % length;
temp2 = stringData[K];
stringData[K] = temp1;
J = K;
temp1 = temp2;
if (J == index0)
{
J++;
index0 = J;
temp1 = stringData[J];
}
}
return 1;
}
, , , . , , , , .
value = length - ((0 - value)% length): , , , . : 10 -9 , +1. -19 , .
value = value% length: , , . , .
, , , . , . , . , , , , . index0 , . , . ,
, . J - . J . . K - , J . . K . J K, . , , J K, - , , temp1 .
temp1 temp2.
, , , . . J reset . .
The video can be found here: https://www.youtube.com/watch?v=TMzaO2WzR24