링크 된 목록의 첫 번째 요소를 가리키는 "* FIRST"포인터를 어떻게 삭제합니까? 첫 번째 요소를 삭제하려면?체인 된 목록의 노드 삭제
-my 문제는 첫 번째 노드를 삭제할 때 포인터가 두 번째 노드에서 가리키는 점입니다. 그러나 내가 가리키는 요소의 주소를 표시하면 FIRST = NULL이 발견됩니다.
미리 감사드립니다.
#include <stdio.h>
#include <stdlib.h>
typedef struct
{int note;
struct personne *next;
}personne;
personne *first=NULL;
void saisi (personne *first,int mark)
{ personne *nouveau=malloc(sizeof(personne));
nouveau->note=mark;
nouveau->next=NULL;
if(first==NULL)
first=nouveau; // here is the problem
else
{ personne *tmp;
tmp=first;
while (tmp->next!=NULL) tmp=tmp->next;
tmp->next=nouveau;
}
}
void affichage (personne *first)
{int i=1;
personne *tmp;
tmp=first;
do
{printf("la note %d : %d \n",i,tmp->note);
i++;tmp=tmp->next;
}while (tmp!=NULL);
}
void suppresion (personne *first,int n)
{personne *tmp1=NULL,*tmp2=NULL;
tmp1=first;
while (tmp1 != NULL)
{ if ((tmp1->note) >n){
tmp2->next=tmp1->next;
}
tmp2=tmp1;
tmp1=tmp1->next;
}
}
int main()
{
int N=1,mark=0,n=0;
while (N!=4)
{ printf ("donner la note %d:",N);
scanf ("%d",&mark);
saisi (first,mark);
N++;
}
affichage (first);
printf("donner n :");
scanf("%d",&n);
suppresion (first,n);
affichage(first);
return 0;
}