The Queue ADT
Solution
A queue is a collection where items are added at one end, the back, and removed from the other end, the front. enqueue adds an item at the back. dequeue removes the item at the front. front returns the item at the front without removing it. isEmpty reports whether the queue has no items.
Solution
First in, first out. front returns 3.
Solution
dequeue and front. There is no front item to remove or return, so both throw a NoSuchElementException. enqueue(null) throws an IllegalArgumentException.
Solution
public static int dequeue(Queue<Integer> queue) {
int value = queue.front();
queue.dequeue();
return value;
}
Solution
The jobs must print in the order they arrived, first in, first out. A queue only lets the program add at the back and remove from the front, which is all the printer needs, and no part of the program can move a job ahead of the jobs that arrived before it.