@@ -0,0 +1,1380 @@
+package comp2402a3;%0A%0Aimport java.util.AbstractCollection;%0Aimport java.util.Iterator;%0A%0A/**%0A * An implementation of a LIFO Stack as a singly-linked list.%0A *%0A * @param %3CT%3E the class of objects stored in the queue%0A */%0Apublic class SLListStack%3CT%3E extends AbstractCollection%3CT%3E %7B%0A%0A%09class Node %7B%0A%09%09T x;%0A%09%09Node next;%0A%09%7D%0A%09%0A%09Node head;%0A%09Node tail;%0A%09int n;%0A%09%0A%09public Iterator%3CT%3E iterator() %7B%0A%09%09return new SLIterator();%0A%09%7D%0A%0A%09@Override%0A%09public int size() %7B%0A%09%09return n;%0A%09%7D%0A%0A%09/**%0A%09 * Stack peek operation - return head's data element%0A%09 * @return x%0A%09 */%0A%09public T peek() %7B%0A%09%09return head.x;%0A%09%7D%0A%09%0A%09/**%0A%09 * Stack push operation - push x onto the head of the list%0A%09 * @param x the element to push onto the stack%0A%09 * @return x%0A%09 */%0A%09public T push(T x) %7B%0A%09%09Node u = new Node();%0A%09%09u.x = x;%0A%09%09u.next = head;%0A%09%09head = u;%0A%09%09if (n == 0)%0A%09%09%09tail = u;%0A%09%09n++;%0A%09%09return x;%0A%09%7D%0A%0A%09/**%0A%09 * Stack pop operation - pop off the head of the list%0A%09 * @return the element popped off %0A%09 */%0A%09public T pop() %7B%0A%09%09if (n == 0)%09return null;%0A%09%09T x = head.x;%0A%09%09head = head.next;%0A%09%09if (--n == 0) tail = null;%0A%09%09return x;%0A%09%7D%0A%09%0A%09class SLIterator implements Iterator%3CT%3E %7B%0A%09%09protected Node p;%0A%0A%09%09public SLIterator() %7B%0A%09%09%09p = head;%0A%09%09%7D%0A%09%09public boolean hasNext() %7B%0A%09%09%09return p != null;%0A%09%09%7D%0A%09%09public T next() %7B%0A%09%09%09T x = p.x;%0A%09%09%09p = p.next;%0A%09%09%09return x;%0A%09%09%7D%0A%09%09public void remove() %7B%0A%09%09%09throw new UnsupportedOperationException();%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A

Create SLListStack class