struct ListNode *readlist(){
struct ListNode *head=NULL,*rear=NULL,*p;
int x;
scanf("%d",&x);
while(x!=-1){
p=(struct ListNode *)malloc(sizeof(struct ListNode));
p->data=x;
if(head==NULL)
head=rear=p;
else{
rear->next=p;
rear=p;
rear->next=NULL;
}
scanf("%d",&x);
}
return head;
}//顺序输出使用尾插法
struct ListNode *deletem( struct ListNode *L, int m ){
struct ListNode *q,*p;
p=L;
q=L;//使用双指针
while(q){
if(p==q){
if(p->data!=m){
q=p->next;
}
else{
q=p->next;
p->next=NULL;
free(p);
L=p=q;
}
}
else{
if(q->data!=m){
p=p->next;
q=q->next;
}
else{
p->next=q->next;
free(q);
q=p->next;
}
}
}
return L;
}