Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Remov...
分类:
编程语言 时间:
2015-06-05 19:37:00
阅读次数:
147
已知栈的输入序列,给出一个输出序列,检查能否按此顺序输出?怎么做?输入 1 2 3 4 5输出 1 4 3 2 5最大容量3我们把输入和输出都定义为队列( 模仿输入输出流嘛 )再定义一个堆栈,上面的例子该怎么检查呢?要输出的第一个数是1我就从in里取数到stack,直取stack的top元素是1为止...
分类:
其他好文 时间:
2015-06-05 19:23:22
阅读次数:
131
栈的特点是“先进后出”,队列的特点是“先进先出”;向队列中依次添加元素n、m,当删除时,先删除应该是n;向栈1中添加元素n、m,当要删除时,把栈1的元素添加到栈2中,元素n刚好位于栈顶,n就会被先删除,正好实现了队列的特点。代码如下,已测。public class Queue { private Stack stackOne=new Stack();
p...
分类:
其他好文 时间:
2015-06-05 15:47:15
阅读次数:
143
Valid Parentheses
题目:
Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.
The brackets must close in the correct order, “()”...
分类:
其他好文 时间:
2015-06-05 14:07:10
阅读次数:
117
stack, deque 和 queue这三个c++的STL的数据结构很类似但又各有不同。stack是堆栈,没有迭代器,特点是后进先出。用push()将元素压入栈中,top()返回栈顶元素,pop()移除栈顶元素。deque是双端队列,支持迭代器,使用push_back()在队尾添加元素,pop_b...
分类:
其他好文 时间:
2015-06-05 00:16:45
阅读次数:
231
queue单向队列queue 模板类的定义在头文件中。与stack 模板类很相似,queue 模板类也需要两个模板参数,一个是元素类型,一个容器类型,元素类型是必要的,容器类型是可选的,默认为deque 类型。定义queue 对象的示例代码如下:queue q1;queue q2;queue 的基本...
分类:
其他好文 时间:
2015-06-04 22:44:05
阅读次数:
165
#include#include#include#define ERROR 0#define Stack_Init_Size 100#define StackIncerMent 10#define OK 1using namespace std;typedef struct { int *ba...
分类:
其他好文 时间:
2015-06-04 22:40:50
阅读次数:
141
stack栈c++stack(堆栈)是一个容器的改编,它实现了一个先进后出的数据结构(FILO)使用该容器时需要包含#include头文件;定义stack对象的示例代码如下:stacks1;stacks2;stack的基本操作有:1 s.empty() 如果栈为空...
分类:
其他好文 时间:
2015-06-04 22:30:13
阅读次数:
103
#include#include#includeusing namespace std;//判断括号是否能匹配,如果最后栈为空,则括号匹配,否则括号不匹配;int main(){ char ch; stack s; int n; cin>>n; while(n--){ cin>>ch; if(s.....
分类:
其他好文 时间:
2015-06-04 22:26:05
阅读次数:
124
一、list简介List列表类,顺序存储任何对象(顺序不变),可重复。
List是继承于Collection的接口,不能实例化。实例化可以用:
ArrayList(实现动态数组),查询快(随意访问或顺序访问),增删慢。整体清空快,线程不同步(非线程安全)。数组长度是可变的百分之五十延长
LinkedList(实现链表),查询慢,增删快。
Vector(实现动态数组),都慢,被...
分类:
编程语言 时间:
2015-06-04 19:29:38
阅读次数:
160