Exercises 3.3 E7(原创)
来源:互联网 发布:照片拼图软件 编辑:程序博客网 时间:2024/05/29 09:31
E7 Rewrite the methods for queue processing from the text ,using a flag to indicate a full queue instead of keeping a count of the entries in the queue
#include<iostream>
#include<queue>
using namespace std;
#include"Queue.cpp"
typedef int Queue_entry;
enum Error_code(success,underflow,overflow);
int main()
{
const int maxqueue=10;
class Queue
{
public:
Queue();
bool empty()const;
Error_code serve();
Error_code append(const Queue_entry &item);
Error_code retrieve(Queue_entry &item)const;
protected:
int front,rear;
int flag;
Queue_entry[maxqueue];
}
Queue::Queue()
{
flag=1;
rear=maxqueue-1;
front=0;
}
bool Queue::empty()const
{
return flag=1;
}
Error_code Queue::append(const Queue_entry &item)
{
if(flag==1)
{
rear=(rear+1)%maxqueue;
entry[rear]=item;
return success;
}
else return overflow;
}
Error_code Queue::serve()
{
if(flag!=1)
{
front=(front+1)%maxqueue;
return success;
}
else return underflow;
}
Error_code Queue::retrieve(Queue_entry&item)const
{
if(flag!=1)
{
item=entry[front];
return success;
}
else return underflow;
}
- Exercises 3.3 E7(原创)
- Exercises 3.3 E7(转载)
- Exercises 3.3 E7
- Exercises 3.3 E7
- Exercises 3.3 E7
- Exercises 3.3 E7
- Exercises 3.3 E7
- Exercises 3.3 E7
- Exercises 3.3 E7
- Exercises 3.3 E7
- P92 Exercises E7 answer
- Exercises 4.1 E1(原创)
- Exercises 4.1 E2(原创)
- 3.3 E7
- 3.3E7
- 3.3E7
- 3.3 E7
- 3.3E7
- 关于session的详细解释
- Present ViewController详解
- volitale关键字
- Android无线调试——抛开USB数据线
- JMX Server Behind Firewall
- Exercises 3.3 E7(原创)
- Git图文教程详细
- 算法之大整数乘法
- POJ 1067 博弈
- RMAN-05535 AND ORA-00312
- .bash_profile与.bashrc和.profile的区分概念
- [转]恢复视力的方法(500度以下)
- VS2010静态编译生成.exe可执行文件
- Hadoop 子项目HIVE安装版本选择