循环顺序队基本操作

来源:百度知道 编辑:UC知道 时间:2024/05/15 02:14:16
初始化队;
将元素10,20,30,40,50,60,70,80,90入队;
将元素10出队;
取此时的队头元素。
求完整代码!

同学你好,我写了代码,也运行过,正确,希望对你有帮助
#include <iostream>
using namespace std;
template<class Telem>
class SqQueue{
Telem *elem;
int front,rear,count;
const int len;
public:
SqQueue(int maxsz=12):len(maxsz){
elem=new Telem[len];
front=rear=count=0;
}
~SqQueue(){delete []elem;}
void clear(){rear=front=count=0;}
int leng(){return count;}
bool empt(){return (count==0);}
bool full(){return (count>=len);}
bool enque(Telem & el);
Telem dlque();
Telem getf();
};
template <class Telem>
bool SqQueue<Telem>::enque(Telem & el){
if(count>=len) return false;
else{
elem[rear]=el;
rear=(rear+1)%len;
count++;
return true;
}
}
template<class Telem>
Telem SqQueue<Telem>::dlque(){
if(count==0) return NULL;
else{
Telem el=elem[front];
front=(front+1)%len;