typedef struct node
{
int n;
struct node* next;
}
node;
在上面的代码中,struct node
中有struct node* next
。我不明白它的意思。
最佳答案
In the code there is
struct node* next
inside thestruct node
. I don't understand the meaning of it.
解释:
节点 是一个通用术语,用于指代 self referential structure .(点击链接了解更多)
按照定义,
A self referential structure is a typical structure whose definition has one or more of its member as a pointer to its own type.
在你的代码中,next
是结构 struct node
的一个成员,它是指向它自己类型的指针,因此你将它视为指向自身的指针结构内部的方式:
struct node* next;
这就是为什么在struct内部使用struct关键字的原因
目的使用自引用结构:
自引用结构 在构建数据结构方面非常有帮助,例如 linked lists ...事实上,变量 next
是在 linked list 中的 nodes 之间建立链接的非常有用的成员 :)
关于c - 在 struct 中使用 struct 关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37843509/