Question: Complete the below java program by adding the following methods: class Queue { private int front, rear, size; private int arrQ[]; Queue( int s) {
Complete the below java program by adding the following methods:
class Queue {
private int front, rear, size;
private int arrQ[];
Queue(int s) {
front = -1;
rear = -1;
size = s;
arrQ = new int[size];
}
- size() prints the number of elements in the queue. (void method)
- isEmpty() checks if the queue is empty or not. (return type is boolean)
- isFull() checks if the queue is full or not. (return type is boolean)
- front() prints the first element of the queue. (void method)
- enqueue(int item) checks if the queue is not full then add item on the rear. (void method)
- dequeue() checks if the queue is not empty then removes the element on front. (void method)
- display() prints all elements of the queue
- split() splits the elements of the queue in two queues and prints the two queues. (void method).
Ex: q = 10 <-- 20 <-- 30 <-- 40 <-- 50 <-- 60 <-- 70 <-- 80
After calling split method q1 = 10 <-- 20 <-- 30 <-- 40 and q2 = 50 <-- 60 <-- 70 <-- 80
- Main method that calls all the previous methods.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
