Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DATA STRUCTURE LANGUAGE JAVA Q2. (bonus) Write a linked list queue class which has the following: (1) a reference to the front node, (2) a

DATA STRUCTURE
LANGUAGE JAVA
image text in transcribed
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 integer 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 you!) 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. Note: remember you can always reuse your code! You don't have to rewrite your linked list class, just use it to implement the queue;)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions