由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - how to use stack(s) to realize a queque
相关主题
关于thread的stackstatic variable存在heap还是stack?
看了几个kaggle的答题,有点迷惑了how to know the stack size of your system?
C语言的变量都一定要放在stack上吗?请教函数 INIT 怎么能free memory
how much slower: heap vs stack memory allocation?stack/heap corruption
c 里面的local static variable有个关于stack address的问题
请大虾验证!array allocation in c
请帮忙看个thread的问题 (with memory dump)数据结构的Heap和内存中的Heap有没有联系?
弱问一个请教什么时候变量会被load进stack,什么时候进入heap呢?
相关话题的讨论汇总
话题: stack话题: queque话题: pop话题: realize话题: push
进入Programming版参与讨论
1 (共1页)
a*****g
发帖数: 22
1
An interview question. I proposed using two stacks, whenever changing action
(pop->push or push->pop), put all data from one stack to the other. I was
told it was too slow.
Any idea? thanks
t****t
发帖数: 6806
2
一个明显的改进是这样, 每次朝stack A里push (push stack).
pop时,从stack B (pop stack) pop. 如果pop时遇到B为空,则把A搬到B.
这样平均复杂度还是O(1). 不过不能保证每个操作都是O(1).

action

【在 a*****g 的大作中提到】
: An interview question. I proposed using two stacks, whenever changing action
: (pop->push or push->pop), put all data from one stack to the other. I was
: told it was too slow.
: Any idea? thanks

1 (共1页)
进入Programming版参与讨论
相关主题
请教什么时候变量会被load进stack,什么时候进入heap呢?c 里面的local static variable
Sort a stack without using auxiliary stacks or arrays请大虾验证!
问一个private destructor的问题请帮忙看个thread的问题 (with memory dump)
请问一个关于 cost of pointer的问题弱问一个
关于thread的stackstatic variable存在heap还是stack?
看了几个kaggle的答题,有点迷惑了how to know the stack size of your system?
C语言的变量都一定要放在stack上吗?请教函数 INIT 怎么能free memory
how much slower: heap vs stack memory allocation?stack/heap corruption
相关话题的讨论汇总
话题: stack话题: queque话题: pop话题: realize话题: push