-1

I have this c program that delete the first node and show the node head data.

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

I was not able to delete the first node but it give me error of request member 'data' and 'struct'

4

1 回答 1

0

我不明白 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;
}
于 2013-10-25T00:45:58.430 回答