我有这个 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/