redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hashs(哈希类型)。这些数据类型都 支持push/pop、add/remove及...
分类:
其他好文 时间:
2015-07-20 23:19:03
阅读次数:
154
Problem Definition: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto s....
分类:
其他好文 时间:
2015-07-20 22:52:15
阅读次数:
105
用两个栈实现一个队列的功能。解题思路假设两个栈A和B,且都为空。
栈A提供push()功能,栈B提供pop()功能。
入队列:入栈A。
出队列:
如果栈B不为空,直接弹出B的元素。
如果栈B为空,则依次弹出栈A的元素并压入栈B中,再弹出B中的元素。
实现代码#include
#include
using namespace std;template<clas...
分类:
其他好文 时间:
2015-07-20 21:37:21
阅读次数:
101
题目如下:
Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop ...
分类:
其他好文 时间:
2015-07-20 16:46:24
阅读次数:
124
STL中与堆相关的4个函数——建立堆make_heap(),在堆中添加数据push_heap(),在堆中删除数据pop_heap()和堆排序sort_heap():
头文件 #include
下面的_First与_Last为可以随机访问的迭代器(指针),_Comp为比较函数(仿函数),其规则——如果函数的第一个参数小于第二个参数应返回true,否则返回false。
建立堆
make_heap(_First, _Last, _Comp)
默认是建立最大堆的。对int类型,可...
分类:
其他好文 时间:
2015-07-20 16:43:31
阅读次数:
117
代码:
// linkstack.hpp
// 栈类
#pragma once
#include "linklist.hpp"
template
class LinkStack
{
public:
LinkStack();
~LinkStack();
public:
int clear();
int push(T &t);
int pop(T &t);
int top(T &...
分类:
其他好文 时间:
2015-07-20 16:42:58
阅读次数:
95
C++ Primer 学习笔记_11_标准模板库_stack、queue队列容器与priority_queue优先队列容器
1、stack堆栈
stack堆栈是一个后进先出(Last In First Out,LIFO)的线性表,插入和删除元素都只能在表的一端进行。插入元素的一端称为栈顶,而另一端称为栈底。插入元素叫入栈(Push),删除元素叫出栈(Pop)。下图是堆栈示意图...
分类:
编程语言 时间:
2015-07-20 16:42:48
阅读次数:
187
题目用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。思路用栈来模拟队列。我们首先插入一个元素a到stack1中,再压入两个元素bc,此时栈中有元素abc,其中c位于栈顶,而stack2仍然为空。我们试着删除一个元素。按照队列先进先出的原则,我们应该先删除元素a。元素a存放在stack1中且不在栈顶,因此不能直接删除。注意到stack2还未使用,我们把stack1中...
分类:
其他好文 时间:
2015-07-20 16:17:14
阅读次数:
103
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get ...
分类:
其他好文 时间:
2015-07-20 09:16:26
阅读次数:
96