#include<stdio.h>#include<stdlib.h>#defineN9typedefstructnode{intdata;structnode*next;}ElemSN;ElemSN*Createlink(inta[],intn){//逆向创建单向链表inti;ElemSN*h=NULL,*p;for(i=N-1;i>=0;i--){p=(ElemSN*)malloc(sizeof(ElemSN));p->data=a[i];p->next=h;h=p;}returnh;}voidPrintlink(ElemSN*h){ElemSN*p;for(p=h;p;p=p->next)pintf("%2d\n",p->data);}ElemSN*DelSamenode(ElemSN*h,intkey){ElemSN*p,*q;p=h;while(p){//p不为空if(p->data!=key){//未找到keyq=p;//两指针联动p=p->next;}else{//key找到p指针指着keyif(p!=h){//判断是否为头结点不是头结点q->next=p->next;free(p);p=q->next;}else{//是头结点h=h->next;free(p);p=h;}}}returnh;}intmain(void){inta[]={3,2,9,8,9,7,9,6,1};intkey;ElemSN*head;head=Createlink(a,9);printf("key=");scanf("%2d",&key);head=DelSamenode(head,key);Printlink(head);}