总结来说,就是等号赋值右边的指针(节点地址)不变,左边的地址变成右边的。即左边的指针移到右边指针的位置。
(PS. 指针命名时不要用next,会搞混)
#include <iostream>
using namespace std;
struct Node
{
int data;
Node* next;
Node(int x) :data(x), next(NULL){}
};
int main()
{
Node* a = new Node(1);
Node* b = new Node(2);
Node* c = new Node(3);
Node* d = new Node(4);
cout << d->data << " " << a->data << endl;
d = a;
d->data = 333;
cout << d->data << " " << a->data << endl;
a = c;
cout << d->data << " " << a->data << endl;
cout << c->data << endl;
a->next = new Node(888);
cout << c->next->data << endl;
a = a->next;
cout << d->data << " " << a->data << endl;
cout << c->data << endl;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)