[問題] 關於list用於tree的表示
最近在學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
→
10/01 16:42,
6年前
, 1F
10/01 16:42, 1F
→
10/01 16:51,
6年前
, 2F
10/01 16:51, 2F