classMyCircularQueue{private:
vector <int> data;int head;int tail;int count;int size;public:/** Initialize your data structure here. Set the size of the queue to be k. */MyCircularQueue(int k){
data.resize(k);
head =0;
tail =-1;
count =0;
size = k;}/** Insert an element into the circular queue. Return true if the operation is successful. */boolenQueue(int value){if(isFull()){returnfalse;}
tail =(tail +1)% size;
data[tail]= value;
count++;returntrue;}/** Delete an element from the circular queue. Return true if the operation is successful. */booldeQueue(){if(isEmpty()){returnfalse;}
head++;
count--;returntrue;}/** Get the front item from the queue. */intFront(){if(isEmpty()){return-1;}return data[head];}/** Get the last item from the queue. */intRear(){if(tail <0&& tail >= size){return-1;}if(isEmpty()){return-1;}return data[tail];}/** Checks whether the circular queue is empty or not. */boolisEmpty(){return(count ==0);}/** Checks whether the circular queue is full or not. */boolisFull(){return(count == size);}};
问题描述:代码:class MyCircularQueue {private: vector <int> data; int head; int tail; int count; int size;public: /** Initialize your data structure here. Set the size of the queue to be k. */ MyCircularQueue(int k) { data.resize(k); head =