顺序队列各种基本运算算法的实现
顺序队列是较为普遍的一种队列实现方式,采用环状数组来存放队列元素,并用两个变量分别指向队列的前端(front)和尾端(rear),往队列中加进或取出元素时分别改变这两个变量的计数(count)。
队列中用环状数组存储数据(合理利用空间、减少操作),通过基本的append()将元素加入队列,serve()将元素移出队列,先进入的先移出,retieve得到最先加入队列的元素。此外在继承的Extended_queue()中我增加了empty()和serve_and_retrieve()的功能。

【实验说明】
我选择的题目:课本中Programming Projects 3.3 P1
问题描述:Write a function that will read one line of input from the terminal. The input is supposed to consist of two parts separated by a colon ':'. As its results, your function should produce a single character as follows:
N No colon on the line.
L The left part(before the colon) is longer than the right.
R The right part(after the colon) is longer than the left.
D The left and right parts have the same length but are different.
S The left and right are exactly the same.
Examples:

Use either a queue or an extended queue to keep track of the left part of the line while reading the right part.
1.分析队列要实现的基本功能以及继承的类要拓展的功能从而确定基本成员函数——append(),serve(),retireve(),拓展队列中:empty(),serve_and_retrieve(),确定队列中以环形数组存储数据从而确定成员函数——Queue_entry entry[],count(记录队列中数据数量)
2.编写队列的头文件及实现
3.分析题目中结束程序并输出几种字母的条件,简略画出功能实现的流程图,编写程序。(具体思路见源代码注释)
4.简单测试程序的几种情况,分析需要改进的地方

【相关代码】
queue.h
[cpp] view plaincopyprint
#ifndef QUEUE_H
#define QUEUE_H
const int maxqueue=10;
enum Error_code {success,overflow,underflow};
typedef char Queue_entry ;
class Queue{
public:
Queue();
bool empty() const;
Error_code append(const Queue_entry &item);
Error_code serve();
Error_code retrieve(Queue_entry &item)const;
protected:
int count;
int front,rear;
Queue_entry entry[maxqueue];
};
class Extended_queue:public Queue{
public:
bool full()const;
int size()const;
void clear();