hui


私信TA

用户名:huih

访问量:4301

签 名:

等  级
排  名 236
经  验 5993
参赛次数 2
文章发表 14
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

#include <bits/stdc++.h>
using namespace std;
typedef struct Node{
int data;
Node *prev,*next;
}Node,*LinkList;
bool init(LinkList &L){
L=(Node *)malloc(sizeof(Node));
if(L==nullptr)return false;
L->next=L;
L->prev=L;
return true;
}
bool insert(LinkList &L,int i,int e){
int pos=0;
Node *p=L;
while(p!=nullptr&&pos<i-1){
pos++;p=p->next;
}
if(p==nullptr)return false;
Node *s=(Node *)malloc(sizeof(Node));
s->data=e;
s->next=p->next;
s->prev=p;
p->next->prev=s;
p->next=s;
return true;
}
bool deletes(LinkList &L,int i){
int pos=0;
Node *p=L;
while(p!=nullptr&&pos<i){
pos++;p=p->next;
}
if(p==nullptr)return false;
p->next->prev=p->prev;
p->prev->next=p->next;
free(p);
return true;
}
void print(LinkList L){
Node *p=L->next;
while(p!=L){
cout<<p->data<<' ';
p=p->next;
}
cout<<'\n';
}
int main() {
LinkList L;
init(L);
int op,i,e;
while(~scanf("%d",&op)){
if(op==0){
print(L);
}
if(op==1){
cin>>i>>e;
insert(L,i,e);
}
if(op==2){
cin>>i;
deletes(L,i);
}
}
    return 0;
}
 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区