Answer:
int n = elements.length;
if(rear < n) {
rear = (rear + 1) % n;
elements[rear] = element;
rear = rear + 1;
}
Explanation:
Options are not made available; However, I'll answer the question base on the following assumptions.
Assumptions
Array name = elements
The front and the rear variable hold the current indices elements
Element to enqueue is "element" without the quotes
To enqueue means to add an element to an already existing queue or to a new queue.
But first, the queue needs to be checked if it can accept a new element or not; in other words, if it's full or not
To do this, we check: if rear < the length of the queue
If this statement is true then it means the array can accept a new element; the new element will be stored at elements[rear] and the rear will be icremented by 1 rear by 1
Else if the statement is false, then an overflow is said to have occurred and the element will not be added.
Going by the above explanation, we have
int n = elements.length;
if(rear < n) {
rear = (rear + 1) % n;
elements[rear] = element;
rear = rear + 1;
}
Additional explanation:
The first line calculates the length of the queue
The if condition on line 2 tests if the array can still accept an element or not
Let's assume this statement is true, then we move to liine 3
Line 3 determines the new position of rear.
Let's assume that n = 6 and current rear is 4.
Line 3 will produce the following result;
rear = (rear + 1) % n;
rear = (4 + 1)% 6
rear = 5%6
rear = 5.
So, the new element will be added at the 5th index
Then line 4 will be equivalent to:
elements[rear] = element;
elements[5] = element;
Meaning that the new element will be enqueued at the 5th index.
Lastly, rear is incremented by 1 to denote the new position where new element can be added.