#include<iostream.h>
struct L
{
int data;
L * next;
};
L * head;
L * create()
{
L * ps;
L * pend;
cout<<"please input a data:"<<endl;
ps=new L;
cin>>ps->data ;
pend=ps;
while (ps->data !=0)
{
if (head==0)
head=ps;
else
pend->next =ps;
pend=ps;
ps=new L;
cin>>ps->data ;
}
pend->next =0;
delete ps;
return head;
}
void show ( L * head)
{
cout<<"the list is:"<<endl;
while ( head)
{
cout<<head->data<<endl ;
head=head->next ;
}
}
void Delete ( L * head, int num)
{
L * p;
if (!head)
{
cout<<"list is null"<<endl;
}
if (head->data ==num)
{
p=head;
head=head->next ;
delete p;
cout<<" the num is delete "<<endl;
}
//else
for ( L * s=head; s->next ;s=s->next )
{
if (s->next->data =num)
s->next =p;
s->next =p->next ;
delete p;
cout<<"the num is delete:"<<endl;
}
cout<<"the num isnot find:"<<endl;
}
void main()
{
int num;
L * head=create();
show (head);
cout<<"please input a num what you want to delete:"<<endl;
cin>>num;
Delete (head,num);