标签:
思想分析:
实现方案:
class MinStack { public: MinStack() {} void push(int x) { if (StackNum.empty()) { StackNum.push(x); StackMin.push(x); } else { if (x <= StackMin.top()) StackMin.push(x); StackNum.push(x); } } void pop() { if (StackMin.top() == StackNum.top()) StackMin.pop(); StackNum.pop(); } int top() { return StackNum.top(); } int getMin() { return StackMin.top(); } protected: stack<int> StackNum; stack<int> StackMin; };
标签:
原文地址:http://www.cnblogs.com/shihaochangeworld/p/5665086.html