由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 求解。。。
相关主题
Time complexity一道google面试题
借人气,问道题几道面试小题
求最大值的问题,很弱,轻拍,多谢各位大神了!发几道Google面试题(Phone and Onsite)
fb面经,附答案,求大牛指点Google电话面试题目
面试题[合集] Google电话面试题目
A Google question[合集] bloomberg面试教训
英语理解力太烂: 题目看不懂The staff is so ....
G家intern电面新鲜面经BST面试题
相关话题的讨论汇总
话题: container话题: returns话题: parent话题: getparent
进入JobHunting版参与讨论
1 (共1页)
l******e
发帖数: 42
1
/* There exists the following interface
public interface Container {
Container getParent(); //if there is no parent, getParent() returns null
String getName();
}
Create a method printContainers(Container c) that prints out the names of
all the parent containers in the order of the top-most parent container
first.
For example, assume the following:
a.getParent() returns b
a.getName() returns "foo"
b.getParent() returns null
b.getName() returns "bar"
printContainers(a) should print to the console:
"bar"
"foo"
*/
l******e
发帖数: 42
2
I figured something like this may work. Please point out anything you see to
correct or improve. thanks!
/////this is a recursive function question
static void printContainer ( Container c)
{
public Stack nameStack = new Stack();
parent1st(c);
while (!nameStack.empty()) {
system.out.println (NameStack.pop());
}
}
static void parent1st(Container c)
{
nameStack.push(c.getName());
if (c.getParent() == null)
return;
else
parent1st((c.getParent());
}
1 (共1页)
进入JobHunting版参与讨论
相关主题
BST面试题面试题
讨论一道的BB interview题A Google question
一道老题目英语理解力太烂: 题目看不懂
设计题目的本质问题G家intern电面新鲜面经
Time complexity一道google面试题
借人气,问道题几道面试小题
求最大值的问题,很弱,轻拍,多谢各位大神了!发几道Google面试题(Phone and Onsite)
fb面经,附答案,求大牛指点Google电话面试题目
相关话题的讨论汇总
话题: container话题: returns话题: parent话题: getparent