#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的指针,这样您就可以访问当前元素中的下一个元素