#include <stdio.h>
#include<stdlib.h>
typedef struct _node{
int value;
struct _node *next;
}Node;
typedef struct _list{
Node* head;
}List;
void add(List* pList,int number);
void print(List *pList);
int main () {
List list;
list.head = NULL;
int number;
do{
scanf("%d",&number);
if(number != -1){
add(&list, number);
}
}while(number != -1);
print(&list);
scanf("input a number to be deleted:%d",&number);
Node *p;
Node *q;
for(q = NULL,p = list.head;p;q = p,p = p->next){
if(p->value == number){
if(q){
q->next = p->next;
}else{
list.head= p->next;
}
free(p);
break;
}
}
for(p =list.head;p;q=q){
q = p->next;
free(p);
}
return 0;
}
void add(List* pList,int number){
Node *p = (Node*)malloc(sizeof(Node));
p->value = number;
p->next = NULL;
Node *last = pList->head;
if(last != NULL){
while(last->next){
last = last->next;
}
last->next = p;
printf("add:%i\n",p->value);
}else{
pList->head = p;
}
}
void print(List *pList){
Node *p;
for(p = pList->head;p;p=p->next){
printf("%d\t",p->value);
}
printf("\n");
}