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