Implement Queues / Linked List
Project Description:
In this project, two kinds of queue are implemented: LinkedQueue implements FIFOQueueInterface { .... } and LLQueueItr implements Iterable, FIFOQueueInterface { ... }. Note that FIFOQueueInterface should be described before the two queues are implemented.
Public interface FIFOQueueInterface
{
boolean isEmpty();
void enqueue(T item);
T dequeue();
}
Two queues should implement those three methods, isEmpty(), dequeue() and enqueue(). Both have inner class Node which has data and next with the constructor.
LinkedQueue.java will be defined as follows. The blanks should be filled.
Now, consider LLQueueItr.java. It implements both FIFOQueue and Iterable. The interface FIFOQueue is the same as described above, and the interface Iterable is givenby jdk (java.lang.Iterable). It turns out that LLQueueItr should implements all methods from the both interfaces. The method isEmpty(), enqueue() and dequeue() are defined same as in the class LinkedQueue. In addition to that, according to the API of Iterable, the method, iterator() should be implemented. The API says the method iterator() return an object of Iterator. Iterator is an interface in jdk (java.util.Iterator), and it has three methods, hasNext(), next() and remove(), which should also be implemented.
As a driver program invokes the method, iterator(), which returns an object in Iterator, it will use the returned object to invoke the methods of Iterator class. For example, hasNext() method is used to check if the next node of queue is available. If so, the method next() will return the content of that node and move to the next node. To make this possible, those methods should be implemented in the LLQueueItr class.
Skills required: Java