lily1234

导航

P92 E7

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 fornt,rear;

queue_entry entry[maxqueue];

bool is_empty;};

Queue::Queue()

{rear=-1;front=0;is_empty=true;}

bool Queue::empty()const;

{return is_empty;}

Error_code Queue::append(const queue_entry &item);

if(!empty()&&(rear+1)%maxqueue=front)return overflow;

is_empty=false;

rear=((rear+1)==maxqueue)?0:(rear+1);

entry[rear]=item;

return success;}

Error_code Queue:: serve(){

if(empty())return underflow;

if(rear==front)is_empty=true;

front=((front+1)==maxqueue)?0:(front+1);

return success;}

Error_code Queue::(queue_entry &item)const{

if(empty())return underflow;

item=entry[front];

return success;}

posted on 2013-08-29 22:47  lily1234  阅读(117)  评论(0)    收藏  举报