Do not solve the code just give me a hint where I am going wrong,whether the approach is correct or not???
Doubt in the answer
Follow this approach:
- If value of root’s key is greater than k1, then recursively call in left subtree.
- If value of root’s key is in range, then print the root’s key.
- If value of root’s key is smaller than k2, then recursively call in right subtree.
answer is coming wrong ???
Your code is correct. Only thing is you are not following the output format.
You also need to print ("# Preorder : “) and (”# Nodes within range are : ") as mentioned in the output format. That should give you a correct answer.