//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Queue Class //Description: Implements a Queue Abstract Data Type using a Linked List // for internal storage. //CS 284 //Programmed by Jonathan Voris //2/28/06 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import java.util.LinkedList; public class Queue { private LinkedList items; //no-argument constructor initializes the linked list public Queue() { items = new LinkedList(); } public Object insert(Object item) { items.add(item); return item; } public Object peek() { if (items.size() == 0) {//throw an exception if the queue is peeked at while empty throw new EmptyQueueException(); } return items.getFirst(); } public Object remove() { if (items.size() == 0) {//throw an exception if a remove is attempted while the queue is empty throw new EmptyQueueException(); } return items.removeFirst(); } public int getSize() { return items.size(); } public boolean isEmpty() { if (getSize() == 0) { return true; } else { return false; } } }