C 中的链表
Linked List in C
这是我试图完成的用于构建链表的代码片段。出于某种原因,我在尝试编译代码时不断收到错误 "error: expected ‘;’, identifier or ‘(’ before ‘struct’ "。谁能帮帮我。
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;
};
这是我试图完成的用于构建链表的代码片段。出于某种原因,我在尝试编译代码时不断收到错误 "error: expected ‘;’, identifier or ‘(’ before ‘struct’ "。谁能帮帮我。
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;
};