@@ -0,0 +1,1767 @@
+package comp2402a3;%0A%0Aimport java.util.LinkedList;%0A%0A%0A/**%0A * An implementation of a Stack that also can efficiently return  %0A * the minimum element in the current Stack.  Every operation -%0A * push, pop, peek, and min - must run in constant time%0A *%0A * @param %3CT%3E the class of objects stored in the queue%0A */%0Apublic class MinStack%3CT extends Comparable%3CT%3E%3E extends SLListStack%3CT%3E %7B%0A%09%0A%09// A second %22stack%22 that keeps track of the minimum values%0A%09// The current minimum object is at the head of this list%0A%09private LinkedList%3CT%3E minData = new LinkedList%3C%3E();%0A%09%0A%09%0A%09public T min()%7B%0A%09%09if(minData.isEmpty()) return null;%0A%09%09%0A%09%09return minData.getFirst();%0A%09%7D%0A%09%0A%09@Override%0A%09public T push(T x) %7B%0A%09%09%0A%09%09if(minData.isEmpty() %7C%7C x.compareTo(minData.getFirst()) %3C= 0) %7B%0A%09%09%09// If x is smaller than the current min object%0A%09%09%09// or if the min data stack is empty, need to add one element to it%0A%09%09%09minData.addFirst(x);%0A%09%09%7D%0A%09%09%0A%09%09// Now let the base class add to the main stack%0A%09%09return super.push(x);%0A%09%7D%0A%0A%09@Override%0A%09public T pop() %7B%0A%09%09// Get the object on top of the main stack%0A%09%09T topData = super.peek();%0A%09%09%0A%09%09if(!minData.isEmpty() && topData.compareTo(minData.getFirst()) == 0) %7B%0A%09%09%09// If the object on top is equal to the current min object%0A%09%09%09// remove it from the min data stack%0A%09%09%09minData.remove();%0A%09%09%7D%0A%09%09// Now let the base class remove from the main stack%0A%09%09return super.pop();%0A%09%7D%0A%0A%09public static void main(String%5B%5D args)%7B%0A%09%09%0A%09%09MinStack%3CCharacter%3E stack = new MinStack%3C%3E();%0A%09%09%0A%09%09String datasequence = %22JKLMNFGHICDEBAA%22;%0A%09%09for (int i = 0; i %3C datasequence.length(); i++)%7B%0A%09%09%09stack.push(datasequence.charAt(i));%0A%09%09%09System.out.println(stack + %22, min = %22 + stack.min());%0A%09%09%7D%0A%09%09%0A%09%09while(stack.size() %3E 0) %7B%0A%09%09%09stack.pop();%0A%09%09%09System.out.println(stack + %22, min = %22 + stack.min());%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A

Create MinStack class