数据结构循环结构类

数据结构循环结构类

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;

}

...................................................

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值