#include<bits/stdc++.h>
using namespace std;
struct node{
int n;
node *pnext;
};
node* create(){
node *p=NULL;
p=(node*)malloc(sizeof(p));
return p;
}
void add(node* pp){
node *p=NULL;
node *tem=pp;
int n;
cin>>n;
for(int i=1;i<=n;++i){
p=(node*)malloc(sizeof(p));
cin>>p->n;
p->pnext=NULL;
tem->pnext=p;
tem=tem->pnext;
}
}
node* Find(node *pp){
node *p=(node *)malloc(sizeof(p));
p=pp;//Good
cout<<"输入要查找删除的数:"<<endl;
int m;
cin>>m;
while(p->pnext!=NULL){//Great
if(p->pnext->n==m) {
return p;
}
p=p->pnext;
}
return NULL;
}
//void Delete(node *pp){
// //node *p=Find();
// //node *p=(node*)malloc(sizeof(p));
// node *tem=pp;
// pp=pp->pnext;
// cout<<"输入要删除的数:"<<endl;
// int m;
// cin>>m;
// while(pp!=NULL){
// if(pp->n==m){
// tem->pnext=pp->pnext;
// free(pp);
// pp=tem->pnext;
// }
// pp=pp->pnext;
// tem=tem->pnext;
// }
//}
void Delete(node *pp){
node *pd=Find(pp);
if(pd==NULL) {
cout<<"没有查找到,无法删除"<<endl;
return;
}
node *q=pd->pnext;
pd->pnext=q->pnext;
free(q);
}
void show(node *pp){
node *p=(node*)malloc(sizeof(p));
p=pp->pnext;
while(p!=NULL){
cout<<p->n<<' ';
p=p->pnext;
}
cout<<endl;
}
int main(){
node *p=NULL;
p=create();//pp是头节点的指针
add(p);
show(p);
Delete(p);
show(p);
return 0;
}