qq_40085659 2021-12-16 18:57 采纳率: 72.7%
浏览 13
已结题

二叉树遍历出现了问题


def preoder(root):
    p1=[]
    if root:
        p1.append(root.data)
        p1+=preoder(root.left)
        p1+=preoder(root.right)
        return p1
L1=preoder(B1.rootNode)
print(L1)
Traceback (most recent call last):
  File "D:\The beauty of the algorithm\c3\Binary tree_traverse.py", line 54, in <module>
    L1=preoder(B1.rootNode)
  File "D:\The beauty of the algorithm\c3\Binary tree_traverse.py", line 51, in preoder
    p1+=preoder(root.left)
  File "D:\The beauty of the algorithm\c3\Binary tree_traverse.py", line 51, in preoder
    p1+=preoder(root.left)
  File "D:\The beauty of the algorithm\c3\Binary tree_traverse.py", line 51, in preoder
    p1+=preoder(root.left)
  [Previous line repeated 1 more time]
TypeError: 'NoneType' object is not iterable


  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 系统已结题 12月29日
      • 已采纳回答 12月21日
      • 创建了问题 12月16日

      悬赏问题

      • ¥15 一块GD32F105芯片的主板。怎么找RXD和TXD串口
      • ¥15 磁盘异常导致工业相机GigE传图卡顿
      • ¥20 python中使用chatgpt为什么一直连接失败
      • ¥50 使用grpc遇到的问题
      • ¥100 运算速度优化问题,控制在四秒以内
      • ¥15 如何用matlab画出这样的图
      • ¥15 线性回归问题进行特征缩放后,为什么求得的参数不对了
      • ¥15 python爬取网页信息(主要为期刊影响因子、官网等),已有ISSN进行检索,但爬取过程找不到class该怎么办?
      • ¥15 找出5阶幻方的所有解的个数:275305224
      • ¥20 wireshark无网络波动