怎么移动?我不清楚,还请大家帮忙!!!!!!!!!!
我定义了个
struct Node{
int num;
struct Node *next;
};
typedef Node *List;
并写了个class
class Gather{
public:
Gather& Insert_elem(int);
............
private: List _front; //使用结构体,定义了2个结点
List _rear;
}
在我写成员函数时,有很多,我只举个例子:
如:
Gather& Gather::Insert_elem(int elem)
{ Node *temp= new Node;
temp = _front; //让临时结点指向头结点
......
//在循环中,我要让临时结点向前不断的加
我的办法是:
temp++;
}
我调试并测试后,发现,temp++;是不对的,不能单纯的用temp++;使temp指向temp的下一个
我只好用: temp = temp->next;
这样虽然解决了向前走的问题,可新的问题又来了!
我有时还需要让temp指向它的前一个,显然temp--肯定不行。
又由于我无法保存temp的前一个,所以不能用临时的变量纪录,再指回去的方法。
我向直接在temp上操作!
那我我该怎么做?????????