// 函数功能:将数组元素循环左移或右移一位
/*
输入参数:
输入的数组 Input
输入数组的长度
ShiftN:取值为 1 或 -1 : 1 表示右移, -1表示左移
*/
void shift(int* Input, int n, int shiftN)
{
int temp;
int i;
if( shiftN > 0 )
{
temp = *(Input+n-1);
for(i=n-1;i>0;i--)
*(Input+i) = *(Input+i-1);
*Input = temp;
}
if (shiftN < 0)
{
temp = *Input;
for(i=0;i<n-1;i++)
*(Input+i) = *(Input+i+1);
*(Input+i) = temp;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int a[]={1,2,3,4,5,6,7,8,9};
int n = sizeof(a)/sizeof(int);
int shiftN = -13;
shiftN = shiftN%n;
int i;
for(i=0;i<abs(shiftN);i++)
shift(a,n,shiftN/abs(shiftN));
for(i=0;i<n;i++)
printf("%4d",a[i]);
return 0;
}