Question: java data structure Q2. (bonus) Write a linked list queue class which has the following: (1) a reference to the front node, (2) a reference

java data structure java data structure Q2. (bonus) Write a linked list queue class which

Q2. (bonus) Write a linked list queue class which has the following: (1) a reference to the front node, (2) a reference to the rear node, (3) and size. Implement the following method: . . boolean isEmpty(); //return true if queue is empty, false otherwise int size(); //return the number of elements in the queue void enqueue(int e); //add a new node with element value e to the end of queue int dequeue(); //remove the node at the front of the queue and return its element int first(); //return the element of the node at the front of the queue without removing it int last(); //return the element of the node at the rear of the queue without removing it printQueue. This method should take a queue and print its elements starting from front to the rear of the queue. (Only use queue operations) reverseKQueue. This method should take a queue and an inte k. then it should reverse the order of the first k integers in the queue leaving the rest unchanged. (Only use queue operations, and any necessary data structure) (Hint: Use a stack to help youl) . For example: Input: Q - (10, 20, 30, 40, 50, 60, 70, 80, 90, 100) k=5 Output: Q = [50, 40, 30, 20, 10, 60, 70, 80, 90, 100) Add a test program that creates an empty queue and initialize it. Then it should call printQueue for the created queue. Then asks the user to enter an integer (it should be valid, that is between 1 and size of the queue). Then, call reverse Queue to reverse the first k elements of the queue. Then call printQueue to print the queue after the reverse operation

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!