11.19

include

using namespace std;
struct Node{
int data;
Node *prior;
Node *next;
Node(int val):data(val),prior(nullptr),next(nullptr){}
};
Node *createList(int n,int arr[]){
if(n==0)return nullptr;
Node *head=new Node(arr[0]);
Node *curr=head;
for(int i=1;i<n;++i){
Node *newNode=new Node(arr[i]);
curr->next=newNode;
newNode->prior=curr;
curr=newNode;

}
curr->next=head;
head->prior=curr;
return head;

}
void swapWithPrior(Node&head,Nodep){
if(!head||!p||head->nexthead)return;
Node *pre=p->Prior;
if(pre
head){
Node *prePre=pre->prior;
Node *pNext=p->next;
prePre->next=p;
p->prior=prePre;
}
}

posted @ 2025-11-24 09:28  Cx330。  阅读(3)  评论(0)    收藏  举报