Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม

Postorder Tree Traversal ในโครงสร้างข้อมูล


Post-order Traversal (Recursive)

ลำดับ: Left → Right → Root

Postorder Tree Traversal ในโครงสร้างข้อมูล

ลำดับ: 8, 5, 15, 23, 20, 16, 10

อัลกอริทึม

postorderTraverse(root):
  if root not empty:
    postorderTraversal(left of root)
    postorderTraversal(right of root)
    print root value

โค้ด C++ และ Output

// postorder_traversal: left → right → root
// Output: Post-Order Traversal: 8 5 15 23 20 16 10