剑指OFFER 包含min函数的栈
手动实现栈,考查基本知识的掌握
class Solution {
public:
static const int stack_size = 100000;
int s[stack_size];
int* mytop = s;
void push(int value) {
*mytop = value;
mytop++;
}
void pop() {
if(mytop == s)return;
mytop--;
}
int top() {
return *mytop;
}
int min() {
int res = INT_MAX;
for(int i=0;i<mytop-s;i++)
{
if(s[i]<res)res = s[i];
}
return res;
}
};