Loading... ## Python 版 代码: ```python class mytree: value = '' left = '' right = '' def __init__(self, value, left='', right=''): self.value = value self.left = left self.right = right def xianxu(t:mytree): print(t.value,end=" ") if t.left!='': xianxu(t.left) if t.right!='': xianxu(t.right) def zhongxu(t:mytree): if t.left!='': zhongxu(t.left) print(t.value, end=" ") if t.right!='': zhongxu(t.right) def houxu(t:mytree): if t.left!='': houxu(t.left) if t.right!='': houxu(t.right) print(t.value, end=" ") if __name__ == '__main__': E = mytree(value='E', left='', right='') D = mytree(value='D', left='', right='') C=mytree(value='C',left='',right='') B=mytree(value='B',left=D,right=E) A=mytree(value='A',left=B,right=C) xianxu(A) print() zhongxu(A) print() houxu(A) ``` 输出: ```python A B D E C D B E A C D E B C A ``` ## JavaScript 版 Last modification:November 24th, 2020 at 02:39 pm © 允许规范转载 Support If you think my article is useful to you, please feel free to appreciate ×Close Appreciate the author Sweeping payments Pay by AliPay Pay by WeChat
Comment here is closed