添加最后链接列表

时间:2018-11-26 04:16:23

标签: c++

我有2个功能,AddLast链表:

from the

void Insert_Last1(Node *&pNode, int x) { Node *P; P = CreateNode(x); if (pNode == NULL) { pNode = P; } else { //Node *temp = new Node; //temp = pNode; while (pNode->pNext != NULL) { pNode = pNode->pNext; } pNode->pNext = P; } } void Insert_Last2(Node *&pNode, int x) { Node *P; P = CreateNode(x); if (pNode == NULL) { pNode = P; } else { Node *temp = new Node; temp = pNode; while (temp->pNext != NULL) { temp = temp->pNext; } temp->pNext = P; } } 中变量temp的作用是什么?
变量Insert_Last2有什么影响?
为什么当我将{{1}中的pNode替换为temp中的pNode时,结果是错误的?

Insert_Last1

0 个答案:

没有答案