数据结构循环结构类
template<class DataType>
class Xunhuan{
public:Xunhuan(); //无参构造函数
Xunhuan(DataType a[],int n); //有参构造函数,建立有n个元素的循环链表
~Xunhuan(); //析构函数
int Length(); //求循环链表的长度
DataType Get(int i); //按位查找
int Locate(DataType x); //按值查找
void Insert(int i,DataType x); //插入操作
DataType Delete(int i); //删除操作
void Print(); //输出操作
private:Node<DataType>*first,*rear; //循环链表的头指针和尾指针
};
Xunhuan<DataType>::Xunhuan(DataType a[],int n)
{
first=new Node;
rear=first;
for(i=0;i<n;i++)
{
s=new Node;s->data=a[i];
rear->next=s;rear=s;
}
rear->next=first;
}
int Xunhuan<DataType>::Length()
{
p=first->next;count=0;
while(p!=first)
{
p=p->next;
count++;
}
return count;
}
DataType Xunhuan<DataType>::Get(int i)
{
p=first->next;count=1;
while(p!=first&&count<i)
{p=p->next;
count++;
}
if(p==first)throw"位置";
else return p->data;
}
...................................................