我有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