擅长:python、mysql、java
<p>看起来你的链接列表有两部分。列表节点具有<code>next</code>和<code>item</code>属性,包装对象具有指向<code>first</code>节点的属性。要递归打印列表,需要有两个函数,一个用于处理包装器,另一个用于对节点进行递归处理。</p>
<pre><code>def print_list(linked_list): # Non-recursive outer function. You might want
_print_list_helper(linked_list.first) # to update it to handle empty lists nicely!
def _print_list_helper(node): # Recursive helper function, gets passed a
if node is not None: # "node", rather than the list wrapper object.
print(node.item)
_print_list_helper(node.next) # Base case, when None is passed, does nothing
</code></pre>