我在.c文件中定义了这个结构:
typedef struct node
{
// the value to store in this node
int i;
// the link to the next node in the list
struct node* next;
}
node;
我编写了一个prepend函数,我可以在main中的for循环中使用它来测试一些值:
void prepend(int i)
{
node* newNode = NULL;
if(first->next == NULL)
{
newNode->i = i;
first->next = newNode;
newNode->next = NULL;
}
else
{
newNode->next = first->next;
newNode->i = i;
first->next = newNode;
}
}
我做错了什么?运行程序时出现Segmentation Fault。
编辑:我在程序到达if(first-> next == NULL)
时收到错误答案 0 :(得分:4)