作者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://www.ptt.cc/bbs/Python/M.1506844935.A.D1D.html
→ zerof: 他是 append 在 LTree 的 root 10/01 16:42
→ e12518166339: 我後來看下一章的例子發現,是我搞錯語意 10/01 16:51