C++ C语言中的链表
下面是我试图完成的构建链表的代码片段。由于某些原因,在编译代码时,我一直遇到错误“error:expected';”、identifier或“(”在“struct”之前)。有人能帮我吗C++ C语言中的链表,c++,c,data-structures,linked-list,nodes,C++,C,Data Structures,Linked List,Nodes,下面是我试图完成的构建链表的代码片段。由于某些原因,在编译代码时,我一直遇到错误“error:expected';”、identifier或“(”在“struct”之前)。有人能帮我吗 struct node; struct node* buildList(int x); void push(struct node** headRef, int data); int findLen(struct node** headRef); struct node{ int data; struc
struct node;
struct node* buildList(int x);
void push(struct node** headRef, int data);
int findLen(struct node** headRef);
struct node{
int data;
struct node* next;
}
struct node* buildList(int x){
struct node* head = NULL;
head = malloc(sizeof(struct node));
head->data = x;
head->next = NULL;
return head;
}
尝试在结构声明后加上分号
struct node{
int data;
struct node* next;
};
只是在结构的末尾缺少一个分号,
struct node{….}在C中,你必须在每个结构的末尾放置分号,是的。有一些设计的反例。如果这个问题是关于C,请删除C++标签。另外一个方法是:@ dFuuver,C或C++中也会出现同样的问题。我不完全理解你的抱怨。