天天看點

python中建立和周遊二叉樹

python建立和周遊二叉樹,可以使用遞歸的方式,源代碼如下:

運作程式,建立二叉樹如圖:

python中建立和周遊二叉樹

前序周遊結果為: a  b  c  d  e  f

中序周遊結果為:c  b  d  a  f  e 

後序周遊結果為:c  d  b  f  e  a