我無法將元素添加到單個鏈接列表的末尾。我試圖尋找其他問題,但我無法找到解決方案。我無法將元素添加到C中的鏈接列表末尾
的代碼是:
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node* next;
};
void PushE(struct node** head,int data);
int main(){
struct node* a = NULL;
PushE(&a,3);
PushE(&a,4);
}
void PushE(struct node** headRef, int data){
struct node* current = *headRef;
struct node* nNode;
nNode = (struct node*)malloc(sizeof(struct node));
nNode->data = data;
nNode->next= NULL;
if(current == NULL)
current = nNode;
else{
while(current->next != NULL)
current = current->next;
current->next = nNode;
}
}
誰能幫我實現這一點。
[請參閱爲什麼不投)在'C'的malloc'的返回值('和家人討論。(HTTP: //stackoverflow.com/q/605845/2173917)。 –
「struct node」的定義在哪裏? –
我不知道如何複製粘貼更改簽名.....東西從聲明的中間.... –