#includeiostream
using namespace std;
struct node
{
int date;
struct node *next;
};
void main()
{
node *create();
void output(node *head);
node *del(node *head,int date);
node *head,*p;
int date;
head=create();
output(head);
cout\"请输入要删除的号:\";
cindate;
head=del(head,date);
output(head);
p=new node;
cout\"请输入号:\";
cinp-date;
output(head);
}
node *create()
{
node *head,*p1,*p2;
int n;
head=NULL;n=0;
p1=new node;
cinp1-date;
while(p1-date!=0)
{
n=n;
if(n==1)head=p1;
elsep2-next=p1;
p2=p1;
p1=new node;
cinp1-date;
}
p2-next=NULL;
return head;
}
node *del(node *head,int date)
{
node *p1,*p2;
if(head==NULL) cout\"链表为空\"endl;
else
{
p1=head;
while(p1-date!=date next!=NULL)
{
p2=p1; p1=p1-next;
}
if(p1-date==date)
{
if(head==p1)head=p1-next;
else p2-next=p1-next;
}
else
cout\"no found\"endl;
}
return head;
}
void output(node *head)
{
node *p;
p=head;
while(p!=NULL)
{
coutp-date\" \"endl;
p=p-next;
}
}
|