题解
2023-07-08 15:03:41
发布于:上海
44阅读
0回复
0点赞
# include<iostream>
using namespace std;
struct node{
int data;
node *next;
};
int main(){
int n,m,a,b,t;
node *head,*r,*p,*s;
cin>>n>>m;
head=new node;
head->next=NULL;
r=head;
for(int i=0;i<n;++i){
cin>>t;
p=new node;
p->data=t;
p->next=NULL;
r->next=p;
r=p;
}
for(int i=0;i<m;++i){
cin>>a>>b;
s=new node;
s->data=b;
s->next=NULL;
p=head;
while(p->next->data!=a) p=p->next;
s->next=p->next->next;
p->next->next=s;
}
p=head;
while(p->next!=NULL){
cout<<p->next->data<<" ";
p=p->next;
}
return 0;
}
这里空空如也
有帮助,赞一个