#include<iostream>
using namespace std;
struct Node
{
int data;
Node* pNext;
};
struct List
{
Node* pHead;
Node* pTail;
};
void Init(List &l)
{
l.pHead = l.pTail = NULL;
}
Node* GetNode(int x)
{
Node* p;
p = new Node;
if (p == NULL)
{
cout << "Khong cap phat \n";
return NULL;
}
p->data = x;
p->pNext = NULL;
return p;
}
void AddTail(List &l, Node *q)
{
if (l.pHead == NULL)
l.pHead = l.pTail = q;
else
{
l.pTail->pNext = q;
l.pTail = q;
}
}
void Output(List l)
{
Node *p = l.pHead;
while (p != NULL)
{
cout << p << endl;
cout << p->data << endl;
cout << p->pNext << endl;
p = p->pNext;
}
cout << endl;
}
void main()
{
List l;
Init(l);
Node *a, *b, *c, *d;
a = GetNode(10);
b = GetNode(9);
c = GetNode(8);
d = GetNode(7);
AddTail(l, a);
AddTail(l, b);
AddTail(l, c);
AddTail(l, d);
b = b->pNext;//????
Output(l);
system("pause");
}
Tại sao khi thay b=b->pNext thì in ra không có thay đổi ạ?
012CDA10
10
012CE030
012CE030
9
012CDEA8
012CDEA8
8
012CDCB0
012CDCB0
7
00000000