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];

}

  1. size() prints the number of elements in the queue. (void method)
  2. isEmpty() checks if the queue is empty or not. (return type is boolean)
  3. isFull() checks if the queue is full or not. (return type is boolean)
  4. front() prints the first element of the queue. (void method)
  5. enqueue(int item) checks if the queue is not full then add item on the rear. (void method)
  6. dequeue() checks if the queue is not empty then removes the element on front. (void method)
  7. display() prints all elements of the queue
  8. 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

  1. Main method that calls all the previous methods.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!