CS 231 Lab 6


Your job today is to write a class MyQueue that uses your linked list to support the methods associated with a queue.

Here are the links to the API's for the most recent versions of Java:


  1. Make a file named MyQueue.java. Declare your class:
    public class MyQueue implements Iterable {

    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.

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

  3. Implement the six interface functions. The add and offer methods should put the new node on the end of the queue, and the remove and 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. One good approach would be to have a field that stores a LinkedList object. Your Queue methods can simply call LinkedList methods in the approrpriate manner.

  4. Make sure your iterator loops over the linked list from the head to the tail of the queue.

  5. Thoroughly test all of your methods.

Once you are convinced your Queue is working, you may begin this week's project.