Question: Repeat the previous programming project, but use a circular linked list to implement the queue. Recall from Figure 12.10 that a circular linked list has

Repeat the previous programming project, but use a circular linked list to implement the queue. Recall from Figure 12.10 that a circular linked list has one external reference, which is to the list’s last node.


Previous programming project

For this project, we will create a data structure known as a queue. A queue can be thought of as a line. Items are added at the end of the line and are taken from the front of the line. You will create a class LinkedQueue based on one of the linked-list classes given in this chapter. It should have private attributes for

  • front—a reference to the first node in the linked list of queue items
  • count—the number of items in the queue

and the following operations:

  • addToQueue(item)—adds item to the end of the queue. (Add it at the end of the linked list.)
  • removeFromQueue()—removes the first item from the queue and returns it. If the queue is empty, returns null.
  • isEmpty—returns true if the queue contains no items; otherwise, returns false.

Create a program that demonstrates the methods of the LinkedQueue class.


Figure 12.10

tail

tail

Step by Step Solution

3.33 Rating (156 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the queue using a circular linked list we need to modify the node class and add a refer... View full answer

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 Java An Introduction to Problem Solving and Progra Questions!