擅长:python、mysql、java
<p>您使用<code>None</code>来表示列表中没有其他节点,也就是说,您位于列表的末尾,但是在搜索列表时,您永远不会对此进行测试,因此当您到达末尾时,您尝试调用<code>None.get_data()</code>。解决方案:不要这样做。在</p>
<p>重做循环的一个好方法可能是将<code>while</code>循环改为测试<code>current</code>,并在找到项时使用<code>break</code>退出循环。在</p>
<pre><code>while current is not None:
if current.get_data() == item:
break
else:
previous = current
current = current.get_next()
</code></pre>
<p>你需要重做后面的一些逻辑来解释这个问题。您不需要单独的<code>found</code>标志;您只需检查<code>current</code>。如果是<code>None</code>,则到达列表末尾时没有找到要查找的项。否则,你找到了它,<code>current</code>就是它。在</p>