2021-03-29

//只带一个尾指针的队列循环链表
template<class T>
class CLinkQueue
{
     public:
         CLinkQueue()			//构造函数
         {
              rear=new Node<T>;
              rear->next=rear;
          }
          void EnQueue(T x);		//入队
          T DeQueue();			//出队
          void SetNull();		//置空队
          int GetLength();		//求队长
      private:
          Node<T>*rear;  //队尾指针
}
          
//入队
template<class T>
void CLinkQueue<T>::EnQueue(T x)
{   
     new Node<T>*p=rear;
     rear–>next=new Node<T>;
     rear=rear->next;
     rear->data=x;
     rear->data=p;
}
//出队
template<class T>
T CLinkQueue<T>::DeQueue()
{
     Node<T>*front=rear->next;
     Node<T>*p=front->next;
     if(!p)throw"Underflow";
     front->next=p->next;
     T x=p->next;
     if(!(front->next))rear=front;
     return x;
}
//置空队
template<class T>
void CLinkQueue<T>::SetNull()
{
     rear->next=rear=new Node<T>;
     rear->next=NULL;
}
//求队长
template<class T>
int CLinkQueue<T>::GetLength()
{
     Node<T>*p=rear->next->next;
     int i=0;
     while(p)
     {
          i++;
          p=p->next;
     }
     return i+1;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值