The goal of this lab period is to give you an opportunity to implement a node-based queue.


  1. Make a new folder for this week's project.
  2. 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.

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

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

    You should be able to copy significant amounts of code from your LinkedList.

  5. Make sure your iterator loops over the linked list from the head to the tail of the queue.
  6. Thoroughly test all of your methods. That means you need to write code that causes every line of code to be executed.

When you are done with the lab exercises, you may start on the rest of the project.

© 2018 Caitrin Eaton.