新足迹

 找回密码
 注册

精华好帖回顾

· 兄弟俩抢玩具过程全记录(配台词) (2008-10-27) MaxJay · 各位妈妈看过来:小宝稀里糊涂的发疹经历。 (2008-12-21) little_bw
· [Karen' Kitchen Time] 素裳淡妆——水果泡芙。 (2008-8-8) Tiger_Karen · 我的ebay经历 (2005-11-14) 水晶靴
Advertisement
Advertisement
查看: 1970|回复: 16

[IT] 在线等 - 微软面试问题 - 急 [复制链接]

发表于 2007-11-13 19:18 |显示全部楼层
此文章由 内核 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 内核 所有!转贴必须注明作者、出处和本声明,并保持内容完整
上次电话interview时被问到这个问题,结果回答I don't know. 现在email又来问,各位xdjm快帮忙!多谢了!

Write a function that would:    return the 5th   element from the end in a singly linked list of integers, in one pass, and then provide a set of test cases against that function.
Advertisement
Advertisement

发表于 2007-11-13 19:30 |显示全部楼层
此文章由 riverSide 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 riverSide 所有!转贴必须注明作者、出处和本声明,并保持内容完整
in what language? How about

p5th = null;
pFrom = head;
count = 0;
while (pFrom!=null) {
pFrom = pFrom.next;
count++;
if (count==5) p5th = head;
else if(count>5) p5th = p5th.next;
}
return p5th;

[ 本帖最后由 riverSide 于 2007-11-13 20:34 编辑 ]

发表于 2007-11-13 19:35 |显示全部楼层
此文章由 riverSide 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 riverSide 所有!转贴必须注明作者、出处和本声明,并保持内容完整
抛砖引玉。

发表于 2007-11-13 19:40 |显示全部楼层
此文章由 内核 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 内核 所有!转贴必须注明作者、出处和本声明,并保持内容完整
Yes, in C. That's similar to my code. I just want to know if there's some tricky code to do this in 2 or 3 lines. But it seems that I'm day-dreaming...

Anyway, thanks mate.

Then, what do you think about the test cases? I think if the function prototype is:

PSINGLE_LIST FindLastFifth(PSINGLE_LIST Head);

then the head should be:

1. NULL
2. With 0 elements
3. With 1 elements
4. With 5 elements
5. With 6 elements
6. With 10 elements
7. With random elements

What do you think?

[ 本帖最后由 内核 于 2007-11-13 20:45 编辑 ]

发表于 2007-11-13 19:44 |显示全部楼层
此文章由 内核 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 内核 所有!转贴必须注明作者、出处和本声明,并保持内容完整
原帖由 riverSide 于 2007-11-13 20:30 发表
in what language? How about

p5th = null;
pFrom = head;
count = 0;
while (pFrom!=null) {
pFrom = pFrom.next;
count++;
if (count==5) p5th = head;
else if(count>5) p5th = p5th.next;
...


But BTW, that guy from MS asked me this question on the phone. How could I explain this code just by mouth? So weird...

发表于 2007-11-13 20:12 |显示全部楼层
此文章由 riverSide 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 riverSide 所有!转贴必须注明作者、出处和本声明,并保持内容完整
For test case set, I think
1. NULL
2. With 0 elements
3. With 1 elements
4. With 5 elements
5. With 6 elements

is enough. It's important to initialize list to be testable.


Also I think you can express well in replying email this time.

Good luck.
Advertisement
Advertisement

2008年度奖章获得者

发表于 2007-11-15 22:17 |显示全部楼层
此文章由 degra 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 degra 所有!转贴必须注明作者、出处和本声明,并保持内容完整
" 5th   element from the end, in single pass", I would expect candidate to use recursion

发表于 2007-12-2 21:14 |显示全部楼层
此文章由 内核 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 内核 所有!转贴必须注明作者、出处和本声明,并保持内容完整
原帖由 gandu 于 2007-11-15 23:17 发表
" 5th   element from the end, in single pass", I would expect candidate to use recursion


Recursion will definitely cause stack overflow in Windows kernel. So usually we avoid this when coding.

发表于 2007-12-3 14:47 |显示全部楼层
此文章由 sujiea 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 sujiea 所有!转贴必须注明作者、出处和本声明,并保持内容完整
我考过类似的题,但是要求reverse the list. And the list is a complicated one with sublist inside. Like:

(1,2,3,(1,(1,2)),4,5,.6)

And I think the only way of doing this is to use Recursion. But I lost the points during the interview.
开心是硬道理!

退役斑竹 2007 年度奖章获得者 2008年度奖章获得者 特殊贡献奖章 参与宝库编辑功臣

发表于 2007-12-3 14:51 |显示全部楼层
此文章由 黑山老妖 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 黑山老妖 所有!转贴必须注明作者、出处和本声明,并保持内容完整
Yes, recursion is probably the only way.
Not good programming practice but sometimes unavoidable.

发表于 2007-12-3 14:53 |显示全部楼层
此文章由 cattor 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 cattor 所有!转贴必须注明作者、出处和本声明,并保持内容完整
哪位能不能翻译一下题目啊?什么叫in one pass?什么又是a set of test cases?

是不是表示,你先取一个我看看,然后再给我个一般的方法我可以一直用下去?

[ 本帖最后由 cattor 于 2007-12-3 15:57 编辑 ]
没有图像的签名档,多么凄凉。So...

不知道从什么时候开始,在每一样东西上面都有一个日子,秋刀鱼会过期,肉罐头会过期,连保鲜纸 -- 都会过期,我开始怀疑,在这个世界上,还有什么东西是不会过期的?
Advertisement
Advertisement

参与宝库编辑功臣

发表于 2007-12-3 15:09 |显示全部楼层
此文章由 bffbffbff 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 bffbffbff 所有!转贴必须注明作者、出处和本声明,并保持内容完整
原帖由 gandu 于 2007-11-15 23:17 发表
" 5th   element from the end, in single pass", I would expect candidate to use recursion


发表于 2007-12-3 17:47 |显示全部楼层
此文章由 C.D. 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 C.D. 所有!转贴必须注明作者、出处和本声明,并保持内容完整
if recursion is not allowed. probably we can copy at most 10 elements into 2 size-5 array, 5 elements each time, it is an integer list, so memory shouldn't be too much, the test case would be the different number of elements in the list, total number is: 0, 4, 5, 9, 10, 11, I am from Java background, i don't know whether Microsoft has some built-in library which can help to simplify the task
向死而生

发表于 2007-12-3 19:15 |显示全部楼层
此文章由 jsg 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 jsg 所有!转贴必须注明作者、出处和本声明,并保持内容完整
Bang Ding

发表于 2007-12-3 20:35 |显示全部楼层
此文章由 taoyuan 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 taoyuan 所有!转贴必须注明作者、出处和本声明,并保持内容完整
原帖由 jsg 于 2007-12-3 20:15 发表
Bang Ding

不懂也顶!支持找工!

发表于 2007-12-4 07:49 |显示全部楼层
此文章由 sujiea 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 sujiea 所有!转贴必须注明作者、出处和本声明,并保持内容完整
搂主这道题riverside的方法很好啊。我觉得in one pass是不是就是说一次循环检索完成。
Advertisement
Advertisement

发表于 2007-12-4 19:26 |显示全部楼层
此文章由 C.D. 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 C.D. 所有!转贴必须注明作者、出处和本声明,并保持内容完整
why can't we use recursion?

[ 本帖最后由 C.D. 于 2007-12-4 20:28 编辑 ]

发表回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Advertisement
Advertisement
返回顶部