C 语言中的链表

Linked List in C

本文关键字:链表 语言      更新时间:2023-10-16

这是我尝试完成的用于构建链表的代码片段。 由于某种原因,我在尝试编译代码时不断收到错误"错误:预期的';',标识符或'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;
           };