リンクされたリストの最後に要素を追加できません。私は他の質問を探してみましたが、解決策を見つけることができません。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'はどこに定義されていますか? –
私はコピー貼り付けがどのようにステートメントの真ん中から何か......... ...を変えるのだろうか –