这些函数仅将我的a [] 1位置内的元素向右移动,但我想将它移动4位置。我是一个新手。任何提示或帮助这个家伙?将阵列项目移位4位置
void shiftright (int a[], int size);
int main (void)
{
int a []= {1, 2, 3, 4, 5, 6, 7, 8};
shiftright(a, 8);
for (int i=0; i<8; i++)
{
cout << a[i] << ' ';
}
return(0);
}
void shiftright (int a[], int size)
{
int temp;
int temp1;
for (int i=0; i<(size -1); i++)
{
temp = a[size-1];
a[size-1] = a[i];
a[i] = temp;
}
}
['std :: rotate'](http://en.cppreference.com/w/cpp/algorithm/rotate) – user657267 2014-10-30 05:28:14
call'shiftright'3更多次 – 2014-10-30 05:29:22
哈哈。谢啦。因为我不关心性能问题。这是最好的解决方案。 – afgphoenix 2014-10-30 05:32:03