queue问题E7

#include<iostream>
using namespace std;
const int maxqueue=10;
enum bb{success,overflow,underflow};
class Queue
{
public:
 Queue()
 {
  count=0;
  rear=maxqueue-1;
  front=0;
 }
 bool empty() const
 {
  if((rear+1)%maxqueue==front)
   return true;
  else
   return false;
 }
 bb serve(int &i)
 {
  if((rear+1)%maxqueue==front)
   return underflow;
  i=entry[front];
  count--;
  front=(front+1)%maxqueue;
  cout<<i<<" ";
  return success;
 }
 bb append(const int &i)
 {
  if((rear+2)%maxqueue==front)
   return overflow;
  count++;
  rear=(rear+1)%maxqueue;
  entry[rear]=i;
  return success;
 }
 bb retrieve(int &i)const
 {
  if(count<=0)
   return underflow;
  i=entry[front];
  return success; 
 }
protected:
 int count,front,rear;
 int entry[maxqueue];
};
int main()
{
 int i,n,j;
 Queue a;
 cin>>n;
 for(j=0;j<n;j++)
 {
  cin>>i;
  a.append(i);
 }
 while(!a.empty())
 {
  a.serve(i);
 }
 return 0;
}

posted @ 2013-08-29 10:21  没有颜色  阅读(136)  评论(1)    收藏  举报