| 1 | class MyCircularDeque { |
| 2 | int front; |
| 3 | int rear; |
| 4 | int size; |
| 5 | int capacity; |
| 6 | int deque[]; |
| 7 | public MyCircularDeque(int k) { |
| 8 | deque = new int[k]; |
| 9 | front = 0; |
| 10 | rear = k-1; |
| 11 | size=0; |
| 12 | capacity = k; |
| 13 | } |
| 14 | |
| 15 | public boolean insertFront(int value) { |
| 16 | if(isFull()){ |
| 17 | return false; |
| 18 | } |
| 19 | front = (front - 1 + capacity) % capacity; |
| 20 | deque[front] = value; |
| 21 | size++; |
| 22 | return true; |
| 23 | } |
| 24 | |
| 25 | public boolean insertLast(int value) { |
| 26 | if(isFull()){ |
| 27 | return false; |
| 28 | } |
| 29 | rear = (rear + 1) % capacity; |
| 30 | deque[rear] = value; |
| 31 | size++; |
| 32 | return true; |
| 33 | } |
| 34 | |
| 35 | public boolean deleteFront() { |
| 36 | if(isEmpty()){ |
| 37 | return false; |
| 38 | } |
| 39 | front = (front + 1 ) % capacity; |
| 40 | size--; |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | public boolean deleteLast() { |
| 45 | if(isEmpty()){ |
| 46 | return false; |
| 47 | } |
| 48 | rear = (rear - 1 + capacity) % capacity; |
| 49 | size--; |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | public int getFront() { |
| 54 | if(isEmpty()){ |
| 55 | return -1; |
| 56 | } |
| 57 | return deque[front]; |
| 58 | } |
| 59 | |
| 60 | public int getRear() { |
nothing calls this directly
no outgoing calls
no test coverage detected