#include<stdio.h>
#include<stdlib.h>
typedef struct employ
{
int reg;
int sal;
char *name;
struct employ *next; // I want to know the purpose of this line
}EMP;
int main(void)
{
EMP *first,*emp1,*emp2,*emp3,*ans;
first = (EMP *)malloc(sizeof(EMP));
first->next = NULL;
/////first///////
emp1 = (EMP *)malloc(sizeof(EMP));
if(emp1 == NULL)
{
perror("malloc error");
exit(1);
}
emp1->reg = 100;
emp1->sal = 30000;
emp1->name = "james";
emp1->next = first;
first = emp1;
/* I havent completed the program bcoz its not necessary here */
最佳答案
在链表中,每个节点都包含一个指向下一个节点的指针。
struct employ *next;
用于实现该效果
+---------+ +---------+
| Node1 |------->| Node2 |----> ...
+---------+ +---------+
如果你在node1,next是一个指向node2的指针,这样你就可以从当前元素访问下一个元素
关于c - 在链表的 "struct name *next"内添加 "struct name"的目的是什么?我的意思是我实际上无法处理到底发生了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24885063/