Adds an item at the rear of Deque. Return true if the operation is successful.
(int value)
| 45 | |
| 46 | /** Adds an item at the rear of Deque. Return true if the operation is successful. */ |
| 47 | public boolean insertLast(int value) { |
| 48 | |
| 49 | if(this.size == this.capacity) // means queue is full |
| 50 | return false; |
| 51 | |
| 52 | if(rear == -1) { // means queue is empty |
| 53 | arr[0] = value; // add the first element and return true |
| 54 | front = 0; |
| 55 | rear = 0; |
| 56 | this.size ++; |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | if(rear == this.capacity - 1) { // if rear is at last, means we will have to add this element at first |
| 61 | arr[0] = value; // position and make rear as first |
| 62 | rear = 0; |
| 63 | }else { |
| 64 | arr[rear + 1] = value; // if rear is not at last, add to rear + 1 and |
| 65 | rear ++; // increment rear |
| 66 | } |
| 67 | this.size ++; // increase the size and return true |
| 68 | return true; |
| 69 | } |
| 70 | |
| 71 | /** Deletes an item from the front of Deque. Return true if the operation is successful. */ |
| 72 | public boolean deleteFront() { |
nothing calls this directly
no outgoing calls
no test coverage detected