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;
}
Run Code Online (Sandbox Code Playgroud)
我想知道为什么使用“ * addToEmpty”而不是“ addToEmpty”。
“ *”在结构中是什么意思?
我知道这是基本问题。但我找不到答案。
如果您回答我的问题,今天我会过得很好
PS这是c ++代码。
小智 5
这是C(++)[Pun意向]的A和B。
在此函数中,您将返回指向节点结构的指针。
您是在要求我们教您指针的基础知识。看看https://en.cppreference.com/w/cpp/language/pointer或google“在C ++中使用指针”,将对所有内容进行说明。