Write an efficient algorithm to sum of all existing left leaves node in given binary tree.
solving of this problem using recursion are very easy. but here given a iterative solution using stack.
Suppose following nodes are inserted on binary tree.
Result :Sum of all left leaves is 11
View left leaf nodes.
Iterative solution : This given below function accept two parameter.
a) root node of tree and
b) address of stack pointer
Preorder traversal of tree in iterative manner and add this node value.
View nodes and pointers.
Try it Yourself
Program for Sum of all left leaves nodes in existing binary tree.. iterative solution using stack.
Visualize process Try it Yourself
Exercise Solve this problem using inorder and postorder traversal.