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

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

全局:

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

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

x
Implement a MyQueue class which implements a queue using two stacks.

发帖规范:
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.4
下一篇:[第二轮] 3/4-3/10 CareerCup 3.6
🔗
EchoMemory 2013-3-3 21:17:31 | 只看该作者
全局:
In short, use the pop of the second stack to simulate queue.pop() and the push of the first stack to simulate the queue.push(). Values should be copied between two stacks....my poor english....
回复

使用道具 举报

🔗
ryancooper 2013-3-4 09:36:03 | 只看该作者
全局:
Your English is fineI know what you mean
回复

使用道具 举报

🔗
weep_willow 2013-3-6 12:03:29 | 只看该作者
全局:
IDEA: whenever a PUSH operation is needed, just push the element into STACK1; if FRONT operation is needed, then check if STACK2 is empty or not: if YES, then put all elements in STACK1 to STACK2; if NO, just give the TOP of STACK2.

c++ implementation

https://github.com/StanleyLee/CareerCup/blob/master/3_5.cpp
回复

使用道具 举报

🔗
keller2046 2013-3-6 13:33:44 | 只看该作者
全局:
贴个java,请大神指点。

public class MyQueue {

        private Stack<Integer> s1, s2;

        public void enqueue(int x) {
                s1.push(x);
        }

        public int dequeue() {

                if (s2.isEmpty()) {

                        while (!s1.isEmpty()) {
                                s2.push(s1.pop());
                        }
                }

                return s2.pop();
        }

}
回复

使用道具 举报

🔗
keller2046 2013-3-6 13:43:21 | 只看该作者
全局:
keller2046 发表于 2013-3-6 13:33
贴个java,请大神指点。

public class MyQueue {

重新读发帖要求,发现还没有github账号,面壁。。。
回复

使用道具 举报

🔗
champoier 2013-3-7 07:56:37 | 只看该作者
全局:
enqueue:对st1压栈
dequeue:如果st2不是空,pop st2。如果st2是空,把st1所有元素pop并push进st2,然后pop st2.

https://gist.github.com/skxie/780678436c5b8d3bdb9f
回复

使用道具 举报

🔗
lazyGoose 2013-3-7 23:24:30 | 只看该作者
全局:
两个stack,第一个吃,第二个吃 第一个吐出来的,然后再吐
https://gist.github.com/lazyGoose/5108785
回复

使用道具 举报

🔗
moophis 2013-3-8 16:26:34 | 只看该作者
全局:
回复

使用道具 举报

🔗
ThunderXu 2013-3-9 21:03:30 | 只看该作者
全局:
https://gist.github.com/ThunderXu/5124091
same with others

And I think may make a func that runs periodically which pops elements of stack1 to stack2 if stack2 is empty instead of doing this when dequeue.
回复

使用道具 举报

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

本版积分规则

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