struct Node *addToEmpty(struct Node *last, int data)
{
// This function is only for empty list
if (last != NULL)
return last;
// Creating a node dynamically.
struct Node *temp =
(struct Node*)malloc(sizeof(struct Node));
// Assigning the data.
temp -> data = data;
last = temp;
// Creating the link.
last -> next = last;
return last;
}
struct Node *addBegin(struct Node *last, int data)
{
if (last == NULL)
return addToEmpty(last, data);
struct Node *temp =
(struct Node *)malloc(sizeof(struct Node));
temp -> data = data;
temp -> next = last -> next;
last -> next = temp;
return last;
}
我想知道为什么使用“*addToEmpty”而不是“addToEmpty”。
结构体中的“*”是什么意思?
我知道这是基本问题。但我找不到答案。
如果你回答我的问题,我今天会很充实
附注这是 C++ 代码。
最佳答案
这是 C(++) 的 A 和 B [双关语]。
在此函数中,您将返回指向节点结构的指针...
您要求我们教您指针的基础知识。看看https://en.cppreference.com/w/cpp/language/pointer或者谷歌“在 C++ 中使用指针”,所有内容都会得到解释。
关于c - 结构函数中的 '*'是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58910186/