#include<stdio.h>//两种删除代码 #include<stdlib.h> typedef struct num { int num; struct num *next; }link; link* create(int n) { link* head,*node,*now; head =(link*)malloc(sizeof(link)); now=head; for(int i=1;i<=n;i++) { node =(link*)malloc(sizeof(link)); scanf("%d",&node->num); now->next= node; node->next=NULL; now =node; } return head; } void del(int n,link* head,int x) { link* now,*node; node=head; while(node!=NULL&&node->next!=NULL)//因为我只用了一个Node指针,相当于有一个单双数的问题,有段错误,多调试几遍就会发现,所以加了一个判定条件 { if(node->next->num==x) { now= node->next; node->next =now->next; free(now); } node =node->next; } } /*void del(int n,link* head,int x)//而这个函数既有node,又有nope,是一步一步来的,所以一个判定条件就行 { link* now,*node; node=head; link* nope=node->next; while(nope!=NULL) { if(nope->num==x) { node->next =nope->next; free(nope); nope =node->next; } else { node=node->next; nope =nope->next; } } } */ void show(link* head ,int n) { link* node; node=head->next; while (node!=NULL) { printf("%d ",node->num); node =node->next; } } int main() { int n,x; scanf("%d%d",&n,&x); link* a=create(n); del(n,a,x); show(a,n); return 0; }