//创建单循环链表 带头结点,L为头指针
#include<bits/stdc++.h>
using namespace std;
typedef struct Node{
int data;
struct Node *next;
}LNode,*LNodeList;
void Creatlist(LNodeList &L,int n){ //带头结点,L为头指针
L=new LNode;
L->next=L;
LNode *p,*q=L;
while(n--){
p=new LNode;
cin>>p->data;
q->next=p;
p->next=L;
q=p;
}
}
void Insert_List(LNodeList &L,int i,int data){
LNode *p,*pr;
int j;
if(i==1){
p=L;
j=0;
}
else{
p=L->next;
j=1;
}
while(p!=L&&j<i-1){
p=p->next;
j++;
}
pr=new LNode;
pr->data=data;
pr->next=p->next;
p->next=pr;
}
void Delete_idex_List(LNodeList &L,int i){
LNode *p=L,*q=L->next;
int j=1;
while(j<i&&q!=L){
q=q->next;
p=p->next;
j++;
}
p->next=q->next;
delete q;
}
void Delete_data_List(LNodeList &L,int data){
LNode *p=L,*q=L->next;
while(q!=L){
while(q!=L&&q->data!=data){
q=q->next;
p=p->next;
}
if(q==L) break;
p->next=q->next;
delete q;
q=p->next;
}
}
void ShowList(LNodeList L){
LNode *p=L->next;
while(p!=L){
cout<<p->data<<" ";
p=p->next;
}
}
int main(){
LNodeList L;
int n;
cin>>n;
Creatlist(L,n);//创建链表
int i,data;
cin>>i>>data;
Insert_List(L,i,data);//插入
int i_delete,data_delete;
cin>>i_delete;
Delete_idex_List(L,i_delete);//按位删
cin>>data_delete;
Delete_data_List(L,data_delete);//按值删
ShowList(L);
return 0;
}
//创建单循环链表 不带头结点,L为首元指针
#include<bits/stdc++.h>
using namespace std;
typedef struct Node{
int data;
struct Node *next;
}LNode,*LNodeList;
void Creatlist(LNodeList &L,int n){//不带头结点,L为首元指针
L=new LNode;
cin>>L->data;
n--;
L->next=L;
LNode *p,*q=L;
while(n--){
p=new LNode;
cin>>p->data;
q->next=p;
p->next=L;
q=p;
}
}
void Insert_List(LNodeList &L,int i,int data){
LNode *p,*pr;
int j;
if(i==1){
p=L;
while(p->next!=L){
p=p->next;
}
pr=new LNode;
pr->data=data;
p->next=pr;
pr->next=L;
L=pr;
}
else{
p=L;
j=1;
while(j<i-1){
p=p->next;
j++;
if(p==L) break;
}
pr=new LNode;
pr->data=data;
pr->next=p->next;
p->next=pr;
}
}
void Delete_idex_List(LNodeList &L,int i){
LNode *p=L->next,*q=L;
while(p->next!=L) p=p->next;
int j=1;
while(j<i){
q=q->next;
p=p->next;
j++;
if(q==L) break;
}
p->next=q->next;
if(i==1) L=p->next;
delete q;
}
void Delete_data_List(LNodeList &L,int data){
LNode *q=L,*p=L->next;
while(p->next!=L) p=p->next;
do{
while(q->data!=data){
q=q->next;
p=p->next;
if(q==L) break;
}
if(q==L&&q->data!=data) break;
p->next=q->next;
if(q==L) L=q->next;
delete q;
q=p->next;
}while(q!=L);
}
void ShowList(LNodeList L){
LNode *p=L;
do{
cout<<p->data<<" ";
p=p->next;
}while(p!=L);
}
int main(){
LNodeList L;
int n;
cin>>n;
Creatlist(L,n);//创建链表
int i,data;
cin>>i>>data;
Insert_List(L,i,data);//插入
int i_delete,data_delete;
cin>>i_delete;
Delete_idex_List(L,i_delete);//按位删
cin>>data_delete;
Delete_data_List(L,data_delete);//按值删
ShowList(L);
return 0;
}
//创建单循环链表 带头结点,L为尾指针
#include<bits/stdc++.h>
using namespace std;
typedef struct Node{
int data;
struct Node *next;
}LNode,*LNodeList;
void Creatlist(LNodeList &L,int n){//带头结点,L为尾指针
L=new LNode;
L->next=L;
LNode *p;
while(n--){
p=new LNode;
cin>>p->data;
p->next=L->next;
L->next=p;
L=p;
}
}
void Insert_List(LNodeList &L,int i,int data){
LNode *p=L->next,*pr;
int j=0;
while(j<i-1){
p=p->next;
j++;
if(p==L->next) break;
}
pr=new LNode;
pr->data=data;
pr->next=p->next;
p->next=pr;
if(p==L) L=pr;
}
void Delete_idex_List(LNodeList &L,int i){
LNode *p=L->next,*q=L->next->next;
int j=1;
while(j<i&&q!=L->next){
q=q->next;
p=p->next;
j++;
}
p->next=q->next;
if(q==L) L=p;
delete q;
}
void Delete_data_List(LNodeList &L,int data){
LNode *p=L->next,*q=L->next->next;
while(q!=L->next){
while(q!=L->next&&q->data!=data){
q=q->next;
p=p->next;
}
if(q==L->next) break;
p->next=q->next;
if(q==L) L=p;
delete q;
q=p->next;
}
}
void ShowList(LNodeList L){
LNode *p=L->next->next;
while(p!=L->next){
cout<<p->data<<" ";
p=p->next;
}
}
int main(){
LNodeList L;
int n;
cin>>n;
Creatlist(L,n);//创建链表
int i,data;
cin>>i>>data;
Insert_List(L,i,data);//插入
int i_delete,data_delete;
cin>>i_delete;
Delete_idex_List(L,i_delete);//按位删
cin>>data_delete;
Delete_data_List(L,data_delete);//按值删
ShowList(L);
return 0;
}
//创建单循环链表 不带头结点,L为尾指针
#include<bits/stdc++.h>
using namespace std;
typedef struct Node{
int data;
struct Node *next;
}LNode,*LNodeList;
void Creatlist(LNodeList &L,int n){//不带头结点,L为尾指针
L=new LNode;
cin>>L->data;
n--;
L->next=L;
LNode *p;
while(n--){
p=new LNode;
cin>>p->data;
p->next=L->next;
L->next=p;
L=p;
}
}
void Insert_List(LNodeList &L,int i,int data){
LNode *p,*pr;
int j;
if(i==1){
pr=new LNode;
pr->data=data;
pr->next=L->next;
L->next=pr;
}
else{
p=L->next;
j=1;
while(j<i-1){
p=p->next;
j++;
if(p==L->next) break;
}
pr=new LNode;
pr->data=data;
pr->next=p->next;
p->next=pr;
if(p==L) L=pr;
}
}
void Delete_idex_List(LNodeList &L,int i){
LNode *p=L,*q=L->next;
int j=1;
while(j<i){
q=q->next;
p=p->next;
j++;
if(q==L->next) break;
}
p->next=q->next;
if(q==L) L=p;
delete q;
}
void Delete_data_List(LNodeList &L,int data){
LNode *q=L->next,*p=L;
do{
while(q->data!=data){
q=q->next;
p=p->next;
if(q==L->next) break;
}
if(q==L->next&&q->data!=data) break;
p->next=q->next;
if(q==L) L=p;
delete q;
q=p->next;
}while(q!=L->next);
}
void ShowList(LNodeList L){
LNode *p=L->next;
do{
cout<<p->data<<" ";
p=p->next;
}while(p!=L->next);
}
int main(){
LNodeList L;
int n;
cin>>n;
Creatlist(L,n);//创建链表
int i,data;
cin>>i>>data;
Insert_List(L,i,data);//插入
int i_delete,data_delete;
cin>>i_delete;
Delete_idex_List(L,i_delete);//按位删
cin>>data_delete;
Delete_data_List(L,data_delete);//按值删
ShowList(L);
return 0;
}