定义栈的数据结构,要求添加一个min函数,能够得到栈的最小元素。
要求函数min、push以及pop的时间复杂度都是O(1)。
算法:在栈中设置一个辅助栈来保存最小值
代码:
/**
为栈增加一个min函数,获取栈中的最小值,复杂度为1
** author :xiaozhi xiong
** date:2014-02-08
**/
#include "stdio.h"
#includ...
分类:
其他好文 时间:
2015-02-08 11:35:41
阅读次数:
190
第九章 恢复进度: $ git stash list 显示存储的工作进度列表。 $ git stash 保存当前的工作进度,分别对暂存区和工作区的状态进行保存。 $ git stash pop [--index] [] 恢复保存的工作进度,并将恢复的工作进度从存储的工作进度列...
分类:
其他好文 时间:
2015-02-07 13:09:25
阅读次数:
166
As the title described, you should only use two stacks to implement a queue's actions.The queue should support push(element), pop() and top() where po...
分类:
其他好文 时间:
2015-02-07 08:03:40
阅读次数:
143
API:Array.prototype.splice(start, deleteCount, value) 数组操作中有:push、pop、unshift左移出、shift左进入;splice不仅可以完成删除操作,而且还可以从中间加入:当deleteCount参数为0时就可以添加元素进来;
分类:
Web程序 时间:
2015-02-06 18:18:17
阅读次数:
146
The following example shows the effect of the Pop command. using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Med...
Go语言的OOP,接口,接口的组合,基础库的函数及接口如何抽象设计,
这些东西在Go的Heap源码及演示例子处理中,都有很好的展示.
在"container/heap"中,它的接口是如下定义的:
type Interface interface {
sort.Interface
Push(x interface{}) // add x as element Len()
Pop() interface{} // remove and return eleme...
分类:
编程语言 时间:
2015-02-05 16:22:40
阅读次数:
262
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-02-05 13:46:31
阅读次数:
219
一、数据传输指令───────────────────────────────────────它们在存贮器和寄存器、寄存器和输入输出端口之间传送数据.1. 通用数据传送指令.MOV 传送字或字节.MOVSX 先符号扩展,再传送.MOVZX 先零扩展,再传送.PUSH 把字压入堆栈.POP 把字弹出堆...
分类:
编程语言 时间:
2015-02-05 13:12:03
阅读次数:
249
一:简介(来自百科)redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)和zset(有序集合)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,...
分类:
其他好文 时间:
2015-02-04 16:26:51
阅读次数:
153
其实平时用的比较多的应该是push和pop,不过还是都记下来,以便后面使用。shift:删除原数组第一项,并返回删除元素的值;如果数组为空则返回undefinedvar a = [1,2,3,4,5];var b = a.shift(); //a:[2,3,4,5] b:1unshift:将参数添加...
分类:
编程语言 时间:
2015-02-04 16:03:20
阅读次数:
232