em mới học môn cấu trúc dữ liệu và giải thuật, em cần tạo 1 danh sách liên kết đơn kiểu số nguyên, nhưng có dòng code này em không hiểu tại sao phải cấp phát động con trỏ mà trong khi hàm đã return con trỏ.
NODE* CreateNode(int x)
{
NODE* temp = new NODE;
temp->info = x;
temp->pNext = NULL;
return temp;
}
void AddTail(LIST& L, NODE* temp)
{
if (L.pHead == NULL)
L.pHead = L.pTail = temp;
else
{
L.pTail->pNext = temp;
L.pTail = temp;
}
}
void CreateList(LIST& L)
{
int x;
cin >> x;
if (x == -1)
cout << "Empty List.";
else
{
while (x != -1)
{
AddTail(L, CreateNode(x));
cin >> x;
}
}
}