c++ - C 中的链表

标签 c++ c data-structures linked-list nodes

这是我试图完成的用于构建链接列表的代码片段。由于某种原因,我在尝试编译代码时不断收到错误“错误:预期‘;’、标识符或‘(’在‘结构’之前””。有人可以帮助我吗?

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;
           };

关于c++ - C 中的链表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28864444/

相关文章:

c++ - 在 C++ 上的 std::set 中查找并更新自定义对象

c++:搜索忽略重音字符

c++ - 在代码中使用 cin.get() 双倍输出

algorithm - HackerEarth挑战赛——Deepu和Array

c++ - 在结构指针中传递值

c - 没有默认大小写的 Objective-C 枚举 "exhaustive"开关的行为

c++ - 将字符串 "A10"拆分为 char 'A' 和 int 10

c - KL25 DAC 驱动器在示波器上显示无输出

c - 在 C 中重建索引

c# - 搜索数百万文件名的最佳数据结构?