我坚持使用字典格式的给定族树的递归函数(键是父项,值是子项)。
按示例=INDIRECT(C11&"!F3")
这个例子中的亚当有3个孩子,其中一个是克拉拉。她没有孩子等等。非常简单。
现在,对于递归函数。
如果一个人没有孩子,她的家谱的深度是1.如果他有孩子,但没有孙子,深度是2.如果他有孙子而没有孙子,深度是等等。
这不应该有效吗?
family_tree = {"Adam": ["Michael", "Clara", "Daniel"], "Clara": [], "Daniel": ["Elizabeth", "Hans"], etc.}
def children(person):
return family_tree[person]
谢谢! :)
答案 0 :(得分:1)
计算深度的逻辑是:
<div class="header-row" id="header-row" style="padding: 0px; overflow:hidden; height:100px;">
<!-- container-fluid is the same as container but spans a wider viewport,
it still has padding though so you need to remove this either by adding
another class with no padding or inline as I did below -->
<div class="container-fluid" style="padding: 0px;">
<div class="row">
<!-- You originally has it set up for two columns, remove the second
column as it is unneeded and set the first to always span all 12 columns
even when at its smallest (xs). Set the overflow to hidden so no matter
the height of your image it will never show outside this div-->
<div class="col-xs-12">
<a class="navbar-brand logo" href="index.html">
<!-- place your image here -->
<img src="http://placekitten.com/g/1200/600" alt="company logo" style="width: 100%;">
</a>
</div>
</div>
</div>
</div>
答案 1 :(得分:0)
你的问题是最重要的条件:
在内循环中保持耐心。如果有孩子,只需跟踪你到目前为止找到的最大深度。完成循环后,然后添加1并返回。