100分跪求 编程建立一个保存整数的环形队列类

来源:百度知道 编辑:UC知道 时间:2024/05/24 11:46:41
(1)类的名称为LQueue。
(2)类中有一个存放队列元素的整型数组queue[100],整型变量head和tail分别指向队列数组的头部和尾部。
(3)类中有如下成员函数:
LQueue():默认构造函数,初始化head和tail为0;
~Lqueue():析构函数,用输出流cout输出“LQueue Destroyed”;
void Store(int num):把数据加入队尾;
int Fetch():从队列头部取出数据。
bool Empty():判断队列是否为空。
(4)先声明类LQueue,然后在类的外部定义成员变量

好了之后再加分

class LQueue{
private int[] queue;
private int head;
private int tail;
LQueue(){
head=0;
tail=1;
queue=new int[100];
}
~Lqueue(){
delete queue;
}
void Store(int num){
if(Full){
//对列满
return;
}
queue[tail-1]=num;
if(tail==99){
tail=0;
}else{
tail++;
}
}
int Fetch(){
if(Empty){
// 对列空
return -1;
}
int curNum= queue[head];
if(head=99){
head=0;
}else{
head++;
}
return curNum;

}
bool Empty(){
if(tail==0&&head=99){
return true;
}
if((tail-1)==head){
return true;
}
return false;
}
bool Full{
if(tail==head){
return true;
}
return false;
}
}

语法或拼写错误自己修改一下。