/** Initialize your data structure here. Set the size of the queue to be k. */ publicMyCircularQueue(int k) { this.queue = newint[k]; this.total = k; this.head = 0; this.size = 0; }
/** Insert an element into the circular queue. Return true if the operation is successful. */ publicbooleanenQueue(int value) { if (isFull()) { returnfalse; } this.size++; inttail= getTail(); this.queue[tail] = value; returntrue; }
/** Delete an element from the circular queue. Return true if the operation is successful. */ publicbooleandeQueue() { if (isEmpty()) { returnfalse; } this.size--; this.head = (this.head + 1) % this.total; returntrue; }
/** Get the front item from the queue. */ publicintFront() { if (isEmpty()) { return -1; } returnthis.queue[this.head]; }
/** Get the last item from the queue. */ publicintRear() { if (isEmpty()) { return -1; } inttail= getTail(); returnthis.queue[tail]; }
/** Checks whether the circular queue is empty or not. */ publicbooleanisEmpty() { returnthis.size == 0; }
/** Checks whether the circular queue is full or not. */ publicbooleanisFull() { returnthis.total == this.size; }