#include<iostream>
#include<stdlib.h>
using namespace std;
struct stu{
int num;
struct stu *next;
};
struct stu *create(int n)
{
struct stu*head,*p,*q;
head=new stu;
p=head;
q=head->next;
for(int i=0;i<n;i++)
{
q=new stu;
cin>>q->num;
p->next=q;
p=q;
}
p=p->next;
return head;
}
void print(struct stu *head)
{
struct stu *p;
p=head->next;
while(p)
{
cout<<p->num<<"\t";
p=p->next;
}
}
struct stu *del(struct stu *head)
{
struct stu *p,*q;
p=head;
q=head->next;
while(p)
{
if(q->num==4)
{
p->next=q->next;
free(q);
break;
}
p=p->next;
q=q->next;
}
return head;
}
struct stu *chang(struct stu *head)
{
struct stu *p;
p=head;
while (p)
{
if(p->num==7)
{
p->num=2;
}
p=p->next;
}
cout<<endl;
return head;
}
struct stu *add(struct stu *head)
{
struct stu *p,*pnew;
#include<stdlib.h>
using namespace std;
struct stu{
int num;
struct stu *next;
};
struct stu *create(int n)
{
struct stu*head,*p,*q;
head=new stu;
p=head;
q=head->next;
for(int i=0;i<n;i++)
{
q=new stu;
cin>>q->num;
p->next=q;
p=q;
}
p=p->next;
return head;
}
void print(struct stu *head)
{
struct stu *p;
p=head->next;
while(p)
{
cout<<p->num<<"\t";
p=p->next;
}
}
struct stu *del(struct stu *head)
{
struct stu *p,*q;
p=head;
q=head->next;
while(p)
{
if(q->num==4)
{
p->next=q->next;
free(q);
break;
}
p=p->next;
q=q->next;
}
return head;
}
struct stu *chang(struct stu *head)
{
struct stu *p;
p=head;
while (p)
{
if(p->num==7)
{
p->num=2;
}
p=p->next;
}
cout<<endl;
return head;
}
struct stu *add(struct stu *head)
{
struct stu *p,*pnew;
p=head->next;
pnew=new stu; //申请空间
cin>>pnew->num;
while(p!=NULL)
{
if(p->num==8)
{
pnew->next=p->next;
p->next=pnew;
break;
}
p=p->next;
}
return head;
}
struct stu *check(struct stu *head)
{
struct stu *p;
p=head->next;
while(p)
{
if(p->num==2)
{
cout<<"YES";
break;
}
p=p->next;
}
if(p==NULL)
cout<<"NO";
return head;
}
int main()
{
struct stu *head;
head=create(4);
print(head);
head=del(head);
print(head);
head=chang(head);
print(head);
head=add(head);
print(head);
head=check(head);
//print(head);
return 0;
}
pnew=new stu; //申请空间
cin>>pnew->num;
while(p!=NULL)
{
if(p->num==8)
{
pnew->next=p->next;
p->next=pnew;
break;
}
p=p->next;
}
return head;
}
struct stu *check(struct stu *head)
{
struct stu *p;
p=head->next;
while(p)
{
if(p->num==2)
{
cout<<"YES";
break;
}
p=p->next;
}
if(p==NULL)
cout<<"NO";
return head;
}
int main()
{
struct stu *head;
head=create(4);
print(head);
head=del(head);
print(head);
head=chang(head);
print(head);
head=add(head);
print(head);
head=check(head);
//print(head);
return 0;
}