Stack
来源:互联网 发布:手机怎么进电脑版淘宝 编辑:程序博客网 时间:2024/04/28 19:51
Desription of Stack
Stacks are a type of container adaptor, specifically designed to operate in a LIFO context (last-in first-out)。
The underlying container may be any of the standard container class templates or some other specifically designed container class. The only requirement is that it supports the following operations:
- back()
- push_back()
- pop_back()
Operation of Stack
push
pop
The function of Stack:
FILO
C++中的实现
template <class T,class Container = deque<T> >class stack;
- T: Type of the elements.
- Container: Type of the underlying container object used to store and access the elements.
Member functions
- (constructor)
- Construct stack (public member function)
- empty
- Test whether container is empty (public member function)
- size
- Return size (public member function)
- top
- Access next element (public member function)
- push
- Add element (public member function)
- pop
- Remove element (public member function)
Application example:
1) 左右括号匹配问题(见我的数据结构算法库例子大全)
// stack::push/pop#include <iostream>#include <stack>using namespace std;int main (){
cout<<"Please input the expressions"<<endl;
cin<<;
String str;
stack<String> mystack; for (int i=0; i<str.length; ++i) {
if (str[i] =="(")
mystack.push(i);
else if (str[i] ==")")
{
if ( stack.empty() ) {
cout<<"Illegal expression";
return -1;
} else {
cout<<"pop "<<mystack.top();
mystack.pop( );
}
}
return 0;}
Reference:
http://www.cplusplus.com/reference/stack/stack/
- stack
- stack
- stack
- stack
- Stack
- Stack
- Stack
- Stack
- stack
- Stack
- stack
- stack
- Stack
- stack
- Stack
- Stack
- stack
- stack.
- WINCE系统启动时是否clean boot
- Ajax参数的传递(POST及GET提交)
- Ajax基础+Ajax开发中的编码问题
- QQ空间图片查看效果实现
- 杭电ACM题目分类大全
- Stack
- 子衿的事(12)
- ubuntu下用命令行安装Qt
- Ext.grid.GridPanel
- 最近有点乱
- GTK Gossip: GDK 事件結構
- C++类的构造函数、拷贝构造函数、‘=’运算符调用问题
- 后台添加事件
- win2K/win2003终端服务器超出最大允许连接数解决之道全攻略