Repeat the previous programming project, but use a circular linked list to implement the queue. Recall from

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 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

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: