em có hai đoạn code
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;
}
}
biến temp trong đoạn code 2 có ý nghĩa như thế nào vậy ạ, gây ảnh hưởng gì đến biến pNode , theo em nghĩ nó cũng giống pNode nhưng sau khi em thay temp bằng pNode (đoạn code 1) thì nó lại chạy sai kết quả
Input: 1 2 3 4 5
Insert_Last1 ouput : 4 5
Insert_Last2 ouput : 1 2 3 4 5

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?