【墨鳌】【C++手写队列】【空间优化不彻底】
template
class Queue{
private:
vectorq;
int size,top;
public:
Queue(){ top=0;q.clear(); }
int getSize(){ return size; }
bool empty(){ return (size==0)? free():false; }
void push(T x) { q.push_back(x);size++; }
T front(){ return q[top]; }
T pop(){
if(!empty()){
T x=q[top++];
size--;
return x;
}
else{
puts("EMPTY ERROR");
exit(0);
}
}
bool free(){
if(q.size()) {
puts("FREE THE QUEUE");
q.clear();
}
top=0;
return true;
}
};