c - 删除第一个节点并取出头节点数据

标签 c nodelist

我有这个 C 程序,可以删除第一个节点并显示节点头数据。

int Delete(struct node** head){
struct node *temp = headRef;
headRef = headRef->next;
tmp->next=NULL;
free(temp);
int headNode = headRef->data;
return headNode;   }

我无法删除第一个节点,但它给了我请求成员“数据”和“结构”的错误

最佳答案

我不明白 if headRef 来自哪里。

其次,您只需将头节点传递到函数中,因此您需要 struct node* head,而不是struct node** head

这是我的代码,希望对你有帮助。

int Delete(struct node* head) {
    struct node* temp = head;
    struct node* nextNode = head -> next;
    int headData = head -> data;

    temp -> next = NULL;
    free(temp);
    head = nextNode;

    return headData;
}

关于c - 删除第一个节点并取出头节点数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19579173/

相关文章:

c++ - C 和 C++ 中 union 的用途

Javascript - 如何在节点列表/querySelectorAll 中找到当前编号?

Java解析XML : getElementsByTagName returns all elements

dom - 如何获取节点列表中每个元素的 innerHTML

c++ - firebreath npplugin 中的文件写入权限被拒绝

c - C 矩阵中指针的练习

c++ - 如何查询二进制文件的源代码版本

javascript - 单击特定节点时如何更改状态

javascript - 在单击事件上更改元素节点列表的样式

c - 如何测试一个点是否位于其表面由点云定义的 3d 形状内?