Description: Given a tree, print all paths from the root to various leaf nodes.
In the figure below, various root-to-leaf paths:
Consider the following function ‘printpath’ to solve the problem:
/*The array ‘arr’ stores the ‘r’ elements that have been traversed so far from the root-to-leaf.*/
void printpath(struct node *node)
arr[r]=node->data;/*since ‘node’ is being traversed, it must added to the ‘arr’ array*/
if(node->left==NULL && node->right==NULL)
//PRINT ARRAY ‘arr’