/************不带头节点的双向循环链表的基本操作,创建,显示,删除,插入,查找***************************/
#include<iostream>
using namespace std;
class link
{
public:
char data;
link *prve;
link *next;
};
link *head;
void init()
{
head=NULL;
}
void show()
{
link *p=head;
do{
cout<<p->data<<" ";
p=p->next;
}while(p!=head);
cout<<endl;
}
/*****头插法*****************/
void create_head()
{
link *p,*tail;
char s;
int n=0;
cout<<"请输入数据以#结束!"<<endl;
while(cin>>s,s!='#')
{
p=new link;
p->data=s;
n++;
if(n==1)
{
head=p;
tail=p;
}
else
{
p->next=head;
head->prve=p;
head=p;
}
}
head->prve=tail;
tail->next=head;
show();
}
/*****尾插法*****************/
void create_tail()
{
link *p,*tail;
char s;
int n=0;
cout<<"请输入数据以#结束!"<<endl;
while(cin>>s,s!='#')
{
p=new link;
p->data=s;
n++;
if(n==1)
{
head=p;
tail=p;
}
else
{
tail->next=p;
p->prve=tail;
tail=p;
}
}
tail->next=head;
head->prve=tail;
show();
}
void delet()
{
link *p=head;
// int i;
cout<<"请输入数据data"<<endl;
char s;
int n=0;
cin>>s;
do{
if(p->data==s)
{
p->next->prve=p->prve;
p->prve->next=p->next;
n=1;
break;
}
p=p->next;
}while(p!=head);
if(n==1)
show();
else
cout<<"不存在你要删除的数"<<endl;
}
int main()
{
init();
create_head();
create_tail();
delet();
return 0;
}