# 线性表之不带头结点的双向循环链表

```#include<iostream>
using namespace std;
template<typename T>struct node{
T data;
node<T> *prior,*next;
};
{
private:
public:
{
}
{
}
{
if(p!=NULL)
{
p->prior->next=NULL;
do{
p=p->next;
}
while (p!=NULL);
}
}
bool empty()
{
}
{
int i=1;
{
i++;
p=p->next;
}
return i;
}
{
int j=1;
return NULL;
else {
if(i==1)
return p;
do {
j++;
p=p->next;
{
return NULL;
}
else return p;
}
}
bool getElem(int i,T &e)
{
node<T> *p;
return false;
else {
e=p->data;
return true;
}
}
bool Insert(int i,T e)
{
s=new node<T>;
s->data=e;
if(i==1)
{
{
s->prior=s->next=s;
}
else {
s->next->prior=s;
s->next->prior=s;
}
return true;
}
else {
if(p==NULL)
return false;
else {
s->next=p->next;
s->prior=p;
s->next->prior=s;
p->next=s;
return true;
}
}
}
bool deleteElem(int i,T &e)
{
if(p==NULL)
return false;
e=p->data;
if(p->next==p)
{
}
else {
p->prior->next=p->next;
p->next->prior=p->prior;
}
delete p;
return true;
}
void print()
{
if(p!=NULL)
do{
cout<<p->data<<" ";
p=p->next;
cout<<endl;
}
template <class T>
friend  ostream & operator <<(ostream &,nLink<T> &);
template <class T>
};
template <class T>
ostream & operator <<(ostream &out,nLink<T> &a)
{
if(p!=NULL)
{
do{
out<<p->data<<" ";
p=p->next;
}
out<<endl;
return out;
}
template <class T>
{
node<T> *pa,*pb,*p,*t;
p=new node<T>;
t=p;
if(pa)
pa->prior->next=NULL;
if(pb)
pb->prior->next=NULL;
while(pa && pb)
{
if(pa->data<=pb->data)
{
p->next=pa;
pa->prior=p;
p=pa;
pa=pa->next;
}
else {
p->next=pb;
pb->prior=p;
p=pb;
pb=pb->next;
}
}
while (pa)
{
p->next=pa;
pa->prior=p;
p=pa;
pa=pa->next;
}
while (pb)
{
p->next=pb;
pb->prior=p;
p=pb;
pb=pb->next;
}
p->next=t->next;
t->next->prior=p;
}
int main()
{
cout<<"La是否为空?"<<boolalpha<<La.empty ()<<endl;
for(int i=1;i<4;i++)
{
La.Insert(i,i);
}
cout<<La;
for(int i=1;i<4;i++)
{
Lb.Insert(i,i+1);
}
cout<<Lb;
cout<<La;
cout<<Lb;
return 0;
}
//该片段来自于http://outofmemory.cn
```

0人收藏

0

0