栈的pop,min,push
来源:互联网 发布:informix 重启数据库 编辑:程序博客网 时间:2024/05/16 11:28
class stack
{
public:
stack(int size=100)
{
buff=new int[size];
cur=-1;
}
~stack()
{
delete[] buff;
}
void push(int val)
{
buff[++cur]=val;
}
void pop()
{
--cur;
}
int top()
{
return buff[cur];
}
bool empty()
{
return cur==-1;
}
private:
int* buff;
int cur;
}
class stackwithmin
{
public:
stackwithmin()
{
}
~stackwithmin()
{}
void push(int val)
{
s1.push(val);
if(val<=min())
s2.push(val);
}
void pop()
{
if(s1.top()==min())
s2.pop();
s1.pop();
}
int top()
{
return s1.top();
}
bool empty()
{
return s1.empty();
}
int min()
{
if(s2.empty())
return INT_MAX;
else return s2.top();
}
private:
stack s1,s2;
}
{
public:
stack(int size=100)
{
buff=new int[size];
cur=-1;
}
~stack()
{
delete[] buff;
}
void push(int val)
{
buff[++cur]=val;
}
void pop()
{
--cur;
}
int top()
{
return buff[cur];
}
bool empty()
{
return cur==-1;
}
private:
int* buff;
int cur;
}
class stackwithmin
{
public:
stackwithmin()
{
}
~stackwithmin()
{}
void push(int val)
{
s1.push(val);
if(val<=min())
s2.push(val);
}
void pop()
{
if(s1.top()==min())
s2.pop();
s1.pop();
}
int top()
{
return s1.top();
}
bool empty()
{
return s1.empty();
}
int min()
{
if(s2.empty())
return INT_MAX;
else return s2.top();
}
private:
stack s1,s2;
}
0 0
- 栈的pop,min,push
- 设计包含min 函数的栈(push\pop\min)
- push, pop, min 都为O(1)的栈
- 实现包含min,max,push,pop函数的栈
- 带MIN函数的栈实现(push pop min 操作都只花O(1))
- pop push min O(1)
- 实现pop push min操作时间复杂度为O(1)的栈结构
- 定义栈的数据结构在Theta(1)时间复杂度内实现min,pop,push操作
- 满足min.push.pop操作时间复杂度为o(1)的栈
- 实现push pop min皆为O(1)的栈
- 实现一个最小栈的push(int x),pop(),top(),min()方法,要求都是常量时间
- 实现一个栈,要求Push/Pop/Min(返回最小值)的时间复杂度为O(1)
- 实现一个栈的pop,push,Min(最小值),时间复杂度为O(1)
- 实现一个栈,要求push,pop,Min的操作时间复杂度为O(1)
- 实现一个栈, 其 Push,Pop,Min 操作的 时间复杂度 均为 O( 1 )
- 实现一个栈,push、pop、求栈中最小值min的时间复杂度为O(1)
- 设计栈,在O(1)的时间复杂内实现push,pop,min
- 设计包含min函数的栈,要求函数min、push以及pop的时间复杂度都是O(1)
- android Handler的使用(二)
- Android快捷支付SDK Demo resultStatus={4001};memo={参数错误};result={}问题
- 工作中遇到的js小结
- eclipse配置java
- 不一样的90后创业者:创业是另一种生活方式
- 栈的pop,min,push
- 尚学堂马士兵struts2 课堂笔记(一)
- Poj 1964 City Game
- Web开发中常见的java.lang.IllegalStateException错误
- C# FTP/SFTP文件传输控件包File Transfer Pack详细介绍
- BEGIN...END
- 第一集 秦羽 第四章 父子
- 你还记得那个背着你的人吗
- iOS app支付宝接口调用的一点总结(补充支付宝SDK&Demo下载地址)