package queue;
public class MyCircularQueue {
int[] equeue ;
int start=0;
int end = 0;
boolean status = true;
/** Initialize your data structure here. Set the size of the queue to be k. */
public MyCircularQueue(int k) {
equeue = new int[k];
start = end = 0;
status = true;
}
/** Insert an element into the circular queue. Return true if the operation is successful. */
public boolean enQueue(int value) {
if(isFull()){
return false;
}
end = (end+1)%equeue.length;
if(start==end && status) status = false;
equeue[end]=value;
return true;
}
/** Delete an element from the circular queue. Return true if the operation is successful. */
public boolean deQueue() {
if(isEmpty())
return false;
start=(start+1)%equeue.length;
if(start == end && !status) status = true;
return true;
}
/** Get the front item from the queue. */
public int Front() {
if (isEmpty()) return -1;
return equeue[start];
}
/** Get the last item from the queue. */
public int Rear() {
if (isEmpty()) return 4;
return equeue[end];
}
/** Checks whether the circular queue is empty or not. */
public boolean isEmpty() {
if(start==end && status)
return true;
return false;
}
/** Checks whether the circular queue is full or not. */
public boolean isFull() {
if(start==end && !status)
return true;
return false;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
MyCircularQueue obj = new MyCircularQueue(3);
boolean param_1 =obj.enQueue(1);
boolean param_0 =obj.enQueue(2);
boolean param_2 =obj.enQueue(3);
//boolean param_2 = obj.enQueue(4);
System.out.println(param_0);
System.out.println(param_1);
System.out.println(param_2);
System.out.println(obj.isEmpty());
System.out.println(obj.isFull());
}
}