Question: Write a Java program to implement a queue data structure using a singly linked list. You can assume the items to be stored in the

Write a Java program to implement a queue data structure using a singly linked list. You can assume the items to be stored in the queue are distinct positive integers. You do not need to incorporate any ordering of the items. However, the queue must implement a front and a rear. The insert operation will use rear and the delete operation will use front. Restrictions: You are not allowed to use any Java API that supports queue interface or list class, rather you are required to build your own singly linked list by defining a node class and implementing a singly linked list class, followed by using that class to implement the queue. If you wish you may use the singly linked list code provided earlier. Programming: Your driver program must have a main() method that is interactive (menu driven) and should give the following options to a user: i) Insert an item into the queue ii) Delete from the queue iii) Display the item at front iv) Display the item at rear v) Display total number of items currently present in the queue vi) Print the items currently present in the queue, from front to rear vii) Quit Program run: The program should start with the menu and the user should be able to choose any option from the menu. The menu should keep coming back, after producing appropriate output for each user choice, until the user selects Quit option. Also, include proper error checking (for example, when someone tries to delete item from an empty queue, or tries to display items of an empty queue) with appropriate message(s).

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!