我试图尽可能有效地移动我的数组。即时通讯使用指针,现在,有麻烦分配值回我的数组IM:指针移位数组C++
void stack::rotate(int nRotations)
{
if (count <= 1) return;
int *intFrontPtr = &items[top+1].n;
int *intBackPtr = &items[count-1].n;
int temp = 0;
for (int shift = 0; nRotations != 0 ;)
{
if (nRotations > 0) // we rotate left
{
temp = *++intFrontPtr; // give temp the value
items[++shift].n = temp; // debug shows success
if (shift == count) // dont overrun array
{
temp = *intBackPtr;
items[count-1].n = temp;
shift = 0; // reset for another rotation
nRotations--; // decrement we have reached the end
}
}
}
}
如果您接受的答案超过21%,那么您可能会获得更多帮助。 – cdiggins 2009-11-01 04:23:48
而且,如果他不只是一遍又一遍地重复同一个问题... – 2009-11-01 14:03:38
太多没有给出答案...例如,“top”定义在哪里......什么是“n”? – dicroce 2009-11-01 16:49:03