标签:代码 tac ati ret rgs [] ISE title subject
/** * Created by YuKai Fan on 2018/9/5. */ public class MinStack{ Stack<Integer> dataStack = new Stack<>(); Stack<Integer> minStack = new Stack<>(); public static void main(String[] args) { MinStack minstack = new MinStack(); minstack.push(5); minstack.push(7); minstack.push(3); minstack.push(4); /*System.out.println(minstack.pop()); System.out.println(minstack.pop());*/ System.out.println("min="+minstack.min()); } public void push(int num) { dataStack.push(num); if (minStack.isEmpty() || num < minStack.peek()) { minStack.push(num); } else { minStack.push(minStack.peek()); } } public void pop() { dataStack.pop(); minStack.pop(); } public int top() { return dataStack.peek(); } public int min() { return minStack.peek(); } }
标签:代码 tac ati ret rgs [] ISE title subject
原文地址:https://www.cnblogs.com/FanJava/p/9594114.html