gpt4 book ai didi

c++ - C 中的链表

转载 作者:行者123 更新时间:2023-11-30 18:39:42 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com