链表的结构体定义有多种方法,下面是我整理的比较常用的方法:
1.
typedef int ElemType;
struct List{
ElemType data;
struct List *next;
};
typedef struct List *list; //定义指针类型list
list l;
l=(list)malloc(sizeof(List));
2.
typedef int ElemType;
struct List{
ElemType data;
struct List *next;
};
typedef struct List list; //结构体重命名
list *l; //加*表明是指针
l=(list)malloc(sizeof(List));
3.
typedef int ElemType;
typedef struct List{
ElemType data;
struct List *next;
}List,*list; //定义指针类型
list l;
l=(list)malloc(sizeof(List));
希望对大家有用哦!