Given a Binary Tree and a target key, your task is to complete the function printAncestors() that prints all the ancestors of the key in the given binary tree.
1 / \ 2 3 / \ 4 5 / 7 Key: 7 Ancestor: 4 2 1
The function takes 2 arguments as input, first the reference pointer to the root node of the binary tree and a integer value target. There will be multiple test cases and for each test the function will be called seperately.
For each test print all the ancestors of the target vlue in the order of their hierarchy.
1 2 L 1 3 R
1 2 R 1 3 L 2 4 L 2 5 R 4 7 L
4 2 1
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.