---
# System prepended metadata

title: 0622. Design Circular Queue
tags: [Leetcode, Medium, Microsoft]

---

# 0622. Design Circular Queue
###### tags: `Leetcode` `Microsoft` `Medium`
## Code
```java=
class MyCircularQueue {
    int[] arr;
    int front=0, rear=-1, len=0;
    public MyCircularQueue(int k) {
        arr = new int[k];  
    }
    
    public boolean enQueue(int value) {
        if(!isFull()){
            rear = (rear+1)%arr.length;
            arr[rear] = value;
            len++;
            return true;
        }
        return false;
    }
    
    public boolean deQueue() {
        if(!isEmpty()){
            front = (front+1)%arr.length;
            len--;
            return true;
        }
        return false;
    }
    
    public int Front() {
        if(!isEmpty()){
            return arr[front];
        }
        return -1;
    }
    
    public int Rear() {
        if(!isEmpty()){
            return arr[rear];
        }
        return -1;
    }
    
    public boolean isEmpty() {
        return len==0;
    }
    
    public boolean isFull() {
        return len==arr.length;
    }
}
```