队头 front
队尾 rear或tail
类型 Queue_entry
const int max=10; /*******************************/ class Queue{ public: Queue(); bool empty() const;//判断队列是否为空 Error_code append(const Queue_entry &x);//入队 Error_code serve();//出队 Error_code retrieve(Queue_entry &x) const;//检索队头元素 protected: int count; int front,rear; Queue_entry entry[max]; }; /*******************************/ //派生类 Extended_queue class Extende_queue:public Queue{ public: bool full() const;//判断是否满 int size() const;//返回元素个数 void clear();//清空所有元素 Error_code serve_and_retrieve(Queue_entry &item);//检索队头元素并删除 }; /*******************************/ //Queue的实现 Queue::Queue() { count = 0; rear = max-1; front = 0; } bool Queue::empty() const { return count==0; } Error_code Queue::append(const Queue_entry &item) { if(count>=max) return overflow; count++; rear=((rear+1)==max)?0:(rear+1); entry[rear]=item; return success; } Error_code Queue::serve() { if(count<=0) return underflow; count --; front=(front+1)==max?0:(front+1); return success; } Error_code Queue::retrieve(Queue_entry &item) const { if(count<=0) return underflow; item=entry[front]; return success; }