最近因为有一场重要的考试,重新学习一下数据结构,我是使用C语言描述。
//关于typdef在结构体中常见的书写方式
typdef struct Student
{
int sid;
char name[100];
char sex;
}STU,*PSTU; //STU等价于struct Student . *PSTU等价于struct Student*;
//因此我们可以在定义Student的数据类型简写为
STU stu ;
PSTU pStu; //定义指针类型的Student
然而我在写链表节点的时候却一直出现错误,代码如下:
//错误代码
typedef struct node
{
int data;
PNODE pNext;
}NODE,*PNODE;
编译器一直提示我 "error C2061: 语法错误 标识符’PNODE’ ",找不到原因后查阅错误提示。如下
说我没有提前声明,恍然大悟!因为C语言的编译原理,PNODE应该在使用时被提起前声明,或者修改成如下代码:
//修改后的正确代码
typedef struct node
{
int data;
struct node * pNext;
}NODE,*PNODE;