@@ -0,0 +1,1509 @@
+//Java implementation of SpecialStack %0A// Note : here we use Stack class for Stack implementation %0A%0Aimport java.util.Stack; %0A%0A/* A class that supports all the stack operations and one additional %0Aoperation getMin() that returns the minimum element from stack at %0Aany time. This class inherits from the stack class and uses an %0Aauxiliarry stack that holds minimum elements */%0A%0Aclass SpecialStack extends Stack%3CInteger%3E %0A%7B %0A%09Stack%3CInteger%3E min = new Stack%3C%3E(); %0A%09%0A%09/* SpecialStack's member method to insert an element to it. This method %0A%09makes sure that the min stack is also updated with appropriate minimum %0A%09values */%0A%09void push(int x) %0A%09%7B %0A%09%09if(isEmpty() == true) %0A%09%09%7B %0A%09%09%09super.push(x); %0A%09%09%09min.push(x); %0A%09%09%7D %0A%09%09else%0A%09%09%7B %0A%09%09%09super.push(x); %0A%09%09%09int y = min.pop(); %0A%09%09%09min.push(y); %0A%09%09%09if(x %3C y) %0A%09%09%09%09min.push(x); %0A%09%09%09else%0A%09%09%09%09min.push(y); %0A%09%09%7D %0A%09%7D %0A%0A%09/* SpecialStack's member method to insert an element to it. This method %0A%09makes sure that the min stack is also updated with appropriate minimum %0A%09values */%0A%09public Integer pop() %0A%09%7B %0A%09%09int x = super.pop(); %0A%09%09min.pop(); %0A%09%09return x; %0A%09%7D %0A%0A%09/* SpecialStack's member method to get minimum element from it. */%0A%09int getMin() %0A%09%7B %0A%09%09int x = min.pop(); %0A%09%09min.push(x); %0A%09%09return x; %0A%09%7D %0A%0A%09/* Driver program to test SpecialStack methods */%0A%09public static void main(String%5B%5D args) %0A%09%7B %0A%09%09SpecialStack s = new SpecialStack(); %0A%09%09s.push(10); %0A%09%09s.push(20); %0A%09%09s.push(30); %0A%09%09System.out.println(s.getMin()); %0A%09%09s.push(5); %0A%09%09System.out.println(s.getMin()); %0A%09%7D %0A%7D %0A

Create SpecialStack.java