السلام عليكم و رحمة الله و بركاته
أتمنى منكم شرح بسيط لخطوات التنقل على
TREE
حتى افهم و خصوصا لأنها بالريكيرجن..
أرجوكم ..تعقدت من الريكيرجن مع التري
و هذا المثال واضح ..بس اتمنى اعرف وشلون تمشي الدالة
algorithm countLeaves (val tree <node pointer>)
Counts the number of leaves in a binary tree using recursion.
Pre tree is a pointer to a binary tree or subtree.
Post returns count of leaves in tree
1 if (tree is null)
1 return 0
2 end if
3 if (tree-left is null AND tree->right is null)
1 return 1
4 end if
5 return (countLeaves(tree->left)
+ countLeaves(tree->right))
end countLeaves