Java Foundations StackADT.java /** * Defines the interface to a stack collection. * * @author Java Foundations * @version 4.0 */ public interface StackADT<T> { /** * Adds the specified element to the top of this stack. * * @param element element to be pushed onto the stack */ public void push(T element); /** * Removes and returns the top element from this stack. * * @return the element removed from the stack * @throws EmptyCollectionException if the stack is empty */ public T pop(); /** * Returns the top element of this stack without removing it from the stack. * * @return the element on top of the stack. It is not removed from the stack * @throws EmptyCollectionException if the stack is empty */ public T peek(); /** * Returns true if this stack contains no elements. * * @return true if the stack is empty, false if the stack is not empty */ public boolean isEmpty(); /** * Returns the number of elements in this stack. * * @return the number of elements in the stack */ public int size(); } QueueADT.java /** * QueueADT defines the interface to a queue collection. * * @author Java Foundation * @version 4.0 */ public interface QueueADT<T> { /** * Adds one element to the rear of this queue. * * @param element the element to be added to the rear of the queue */ public void enqueue(T element); /** * Removes and returns the element at the front of this queue. * * @return the element at the front of the queue * @throws EmptyCollectionException if the queue is empty */ public T dequeue(); /** * Returns without removing the element at the front of this queue. * * @return the first element in the queue * @throws EmptyCollectionException if the queue is empty */ public T first(); /** * Returns true if this queue contains no elements. * * @return true if the queue is empty, false if the queue is not empty */ public boolean isEmpty(); /** * Returns the number of elements in this queue. * * @return the number of elements in the queue */ public int size(); } LinkedDeque.java public class LinkedDeque<T> implements QueueADT<T>, StackADT<T>, DequeADT<T> { // inner class for a double linked list node private class DNode<T> { private T element; private DNode<T> prev, next; } // data fields for the LinkedDeque class private DNode<T> front, rear; private int size; // deque interface methods @Override public void addFirst(T element) { // create a new node and set it up DNode<T> newNode = new DNode<T>(); newNode.element = element; // from param to new node obj newNode.prev = newNode.next = null; if(this.isEmpty()) { // we are making the only node in the deque this.rear = this.front = newNode; } else { // there already exists a new node // so, put the new node before the front node newNode.next = this.front; this.front.prev = newNode; this.front = newNode; } this.size++; } @Override public T removeFirst() { T grabbedElt = this.getFirst(); // checks for empty for us if.