Due: Monday, April 3, 2017, 11:59 pm

Queues

The goal of this lab period is to give you an opportunity to implement a queue using your own linked list.

Tasks

  1. Make a new folder for this week's project.
  2. Copy LinkedList.java from last week.
  3. Make a file named MyQueue.java. Declare your class:

    public class MyQueue<T> implements Iterable<T>

    Note: Although we are using Java's Queue interface as inspiration, we are not going to implement all of the methods in that interface (specifically, we are ignoring the larger set of Collections methods), so we will not say that our class "implements Queue". It will, however, implement Iterable.

  4. Find the Queue interface documentation and see what the key functions are. What is the difference between them?

  5. Implement the three interface functions that do not throw exception. The offer method should put the new node on the end of the queue, and the poll methods should remove and return the data in the node at the head of the queue.

    Note that you do not need to begin from scratch. Use your LinkedList class from the last project to implement the queue. Your Queue methods can simply call LinkedList methods in the appropriate manner.

  6. Make sure your iterator loops over the linked list from the head to the tail of the queue.
  7. Thoroughly test all of your methods.

Once you are convinced your Queue is working, you may begin Project 6.

© 2017 Ying Li. Page last modified: .