查看: 2397| 回复: 8
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] [第二轮] 3/4-3/10 CareerCup 3.3

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Implement a data structure SetOfStacks that mimics this. SetOfStacks should be composed of several stacks and should create a new stack once the previous one exceeds capacity.SetOfStacks.push() and SetOfStacks.pop() should behave identically to a single stack (that is, pop() should return the same values as it would if there were just a single stack).
FOLLOW UP
Implement a function popAt(int index) which performs a pop operation on a specific sub-stack.


发帖规范:
http://www.1point3acres.com/bbs/thread-48094-1-1.html
http://www.1point3acres.com/bbs/thread-32423-1-1.html

上一篇:[第二轮] 3/4-3/10 CareerCup 3.2
下一篇:[第二轮] 3/4-3/10 CareerCup 3.4
🔗
EchoMemory 2013-3-3 21:07:37 | 只看该作者
全局:
SetOfStacks could be made of two dynamic arrays. if the current stack exceeds the capacity;  push all values to the enough hold stack; enlarge the current stack; push the value in the hold stack to the current stack back.  And SetOfStacks.push() is the current stack.push(); SetOfStacks.pop() is the current stack.pop(). Function popAt(int index) is an easy one, just move.
回复

使用道具 举报

🔗
moophis 2013-3-5 20:58:18 | 只看该作者
全局:
Using a resized array to store the pointers by which linked lists are pointed.
https://github.com/moophis/careercup/blob/master/3.3.cpp
回复

使用道具 举报

🔗
lazyGoose 2013-3-6 08:20:41 | 只看该作者
全局:
Java, use ArrayList<MyStack>();

push()
1. push elements into stack
1. Once a stack is full, put the stack into ArrayList().
2. create a new stack.  GOTO 1.

int pop() & int popAt()
1. Pop stack with function pop() in MyStack
2. Once stack is empty, use the stack in ArrayList()

https://gist.github.com/lazyGoose/5095641
回复

使用道具 举报

🔗
ThunderXu 2013-3-9 14:01:31 | 只看该作者
全局:
https://gist.github.com/ThunderXu/5122917
use a vector<stack> to realize
回复

使用道具 举报

🔗
Fanyare 2013-3-10 05:03:14 | 只看该作者
全局:
回复

使用道具 举报

🔗
cjsp 2013-3-10 10:35:58 | 只看该作者
全局:
本帖最后由 cjsp 于 2013-3-10 10:37 编辑

https://gist.github.com/flatlight/5126804
Stack: array stack
SetOfStacks: linked stack of stacks
回复

使用道具 举报

全局:
https://github.com/1094401996/Ca ... ot3/SetOfStack.java
followup还没写。。。。发现自己理解和答案有出入。。。。想不明白这么好的一本书为什么不完善一下答案。。。
回复

使用道具 举报

🔗
grassgigi 2013-3-14 11:11:16 | 只看该作者
全局:
https://gist.github.com/chrislukkk/5158494

pop和push很简单 加个checkpoint验证threshold就可以了
popAt就直接pop,如果一个stack pop以后为空则删除该stack。
我觉得书上那个rolling over的方法不太好。。还要追踪stack的bottom。。那还是stack嘛。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表