pintia7-2 双向循环链表应用
include
include
using namespace std;
typedef struct fff{
int data;
fff* next;
fff* pre;
}node,*Node;
void build(Node p){
int n;
cin>>n;
while(n--){
int x;
cin>>x;
Node now=new node();
now->data=x;
now->pre=p;
now->next=NULL;
p->next=now;
p=p->next;
}
}
void show(Node p){
p=p->next;
while(p!=NULL){
cout<
p=p->next;
}
}
void change(Node p){
Node o=p;
p=p->next;
p=p->next;
int x;
cin>>x;
while(p!=NULL&&p->data!=x){
p=p->next;
}
if(p==NULL){
cout<<"未找到"<<x;
}
else{
Node pp=p->pre,ppp=pp->pre;
Node a=pp->pre,b=pp,c=p,d=p->next;
ppp->next=p;
pp->pre=c;
pp->next=d;
p->pre=a;
p->next=b;
show(o);
}
}
int main(){
Node p=new node();
p->next=NULL;
build(p);
change(p);
return 0;
}