What is the code below trying to print? [code] void print(tree *root,tree *node) { if(root ==null) return 0 if(root-->left==node ||

Trần Vũ

New member
What is the code below trying to print?
Code:
void print(tree *root,tree *node)
{
  if(root ==null) return 0
  if(root-->left==node || root-->right==node) || print(root->left,node)
  ||printf(root->right,node)
  {
     print(root->data)
  }
}
A. just printing all nodes
B. not a valid logic to do any task
C. printing ancestors of a node passed as argument
D. printing nodes from leaf node to a node passed as argument
 
Answer: C
Explanation: We are checking if left or right node is what the argument sent or else if not the case then move to left node or right node and print all nodes while searching for the argument node.
 

Tìm kiếm

Back
Top