Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please use C language(not C++ or Java) to write a function based on follow question: Give an example (function call and tree) that show each
Please use C language(not C++ or Java) to write a function based on follow question:
Give an example (function call and tree) that show each special case.
Please also give an example (function call and tree) that show each special case.
P5. (25 points) Write a function int follow_path (link root, int * A, int F) that takes as arguments a tree (given by the root node, root), an array, A, and a number, F, and returns the item found in the tree, following the path given by the first F elements of A: - if you see a 0 in A, go left in the tree; - if you see a 1in A go right in the tree. Continue the same way. For the function calls below, assume that root is pointing to the root, 8, of the tree below follow_path (root, [0,1], 2) returns 3 (from root, go left, then right) follow path (root, [1,0], 2) returns 4 follow path (root, [0,1,1,0], 2) returns 3 follow path (root, [1], 1) returns 5 follow path (root, [0,1, 0) returns 8 You can onlv assume that A has at least F elements in it whenever it is called If anything goes wrong in the function call, it should return -1 You can use a helper function if you want. The nodes and links are defined as follows: 4 typedef struct node * link; struct node int data; link left; link rightStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started