using namespace std;
const int N = 10;
class Queue
{
int a[N];
static int cnt;
public:
void push(int b)
{
try{if(cnt==N)
throw 1;}
catch(int)
{
cerr << "this queue is full!";
}
a[cnt++]=b;
}
void pop()
{
try{if(cnt==0)
throw 1;}
catch(int)
{
cerr << "this queue is empty!";
}
--cnt;
}
};
int Queue::cnt=0;
int main()
{
Queue q;
q.pop();
}
入队和出队的时候都检查一下队列元素个数就行了。