Write a function that prints all its root-to-leaf paths.
Difficulty level

This exercise is mostly suitable for students
void printarray(int A[], int size)
{
int i;
for(i=0; i< size; i++)
printf("%d ",A[i]);
printf("\n");
}
void printPath_h(Btree B, int path[], int size)
{
if(B)
{
path[size++]=B->data;
if(!B->left && !B->right)
printarray(path,size);
else
{
printPath_h(B->left, path,size);
printPath_h(B->right, path,size);
}
}
}
void printPath(Btree B)
{
int path[N];
printPath_h(B, path,0);
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
