作者e12518166339 (耐纶)
看板Python
标题[问题] 关於list用於tree的表示
时间Sun Oct 1 16:02:11 2017
最近在学python顺便重看algo的书籍
目前看到第六章这个部份
http://interactivepython.org/runestone/static/pythonds/Trees/ListofListsRepresentation.html
我的疑问是
def insertLeft(root,newBranch):
t = root.pop(1)
if len(t) > 1:
root.insert(1,[newBranch,t,[]])
else:
root.insert(1,[newBranch, [], []])
return root
他先确定了右边节点是否为空
只是if len(t) > 1 时的作法是否应是
root.insert(1,[t,newBranch,[]]) 才是?
因为不为空,表示左子树的根应该为t本身,而不是newBranch?
以上
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 118.167.126.20
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1506844935.A.D1D.html
1F:→ zerof: 他是 append 在 LTree 的 root 10/01 16:42
2F:→ e12518166339: 我後来看下一章的例子发现,是我搞错语意 10/01 16:51