public
class
GFG {
static
class
Node {
public
int
data;
public
Node left, right;
};
static
Node newNode(
int
key)
{
Node temp =
new
Node();
temp.data = key;
temp.left = temp.right =
null
;
return
temp;
}
static
int
findProduct(Node root)
{
if
(root ==
null
)
return
1
;
return
(root.data * findProduct(root.left)
* findProduct(root.right));
}
static
void
display(Node root)
{
if
(root ==
null
)
return
;
display(root.left);
System.out.print(root.data +
" "
);
display(root.right);
}
static
void
convertTree(
int
product, Node root)
{
if
(root ==
null
)
return
;
root.data = product / (root.data);
convertTree(product, root.left);
convertTree(product, root.right);
}
public
static
void
main(String[] args)
{
Node root = newNode(
1
);
root.left = newNode(
2
);
root.right = newNode(
3
);
root.right.left = newNode(
4
);
root.right.right = newNode(
5
);
System.out.println(
"Inorder Traversal of "
+
"given Tree:"
);
display(root);
int
product = findProduct(root);
System.out.println(
"\nInorder Traversal of "
+
"given Tree:"
);
convertTree(product, root);
display(root);
}
}