Question
class Queue { private int front, rear, maxSize; private int queue[]; Queue(int c) { front = 0; rear = -1; maxSize = c; queue =
class Queue { private int front, rear, maxSize;
private int queue[];
Queue(int c) { front = 0; rear = -1;
maxSize = c;
queue = new int[maxSize]; }
Based on the above class declaration, write the following methods.
Write splitQ method that splits the elements of a queue (q1) in two by assigning first half values to a new queue (q2) and keeping only last half values in (q1). (6 points)
Example:
q1 holds 20 <-- 30 <-- 40 <-- 50 <-- 60 <-- 70 After calling split method q2 will hold 20 <-- 30 <-- 40 and q1 will hold 50 <-- 60 <-- 70
void splitQueue(Queue q1){ Queue q2 = new Queue(q1.maxSize);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started