Create tree preorder inorder

i am not able to understand the output function please help me out…

Hello @ankit152,

Following code explains the output format:

Hope, this would help.
Give a like, if you are satisfied.

here what is data? the code is showing undefined symbol data

Hello @ankit152,

So, you didn’t try to understand the code.
You just copied it.:sweat_smile:

Let’s understand the code first:

What are we doing?
you have to consider 4 cases:
2 => 1 <= END
3 => 2 <= END
END => 3 <= END
case 1:
if root->left!=null &&root>right!=null
2 => 1 <= 4
then you have to print values on the both sides and in mid there will be root->data
case 2:
if root->left==null and root->right==null
END => 3 <= END
case 3:
if root->left!=null and root->right==null
2 => 1 <= END
case 4:
if root->left==null and root->right!=null
END => 3 <= 7
Note in mid parent root node will be there.

I think now you can correct the code yourself.
In case you still face any issue, feel free to ask.

Hope, this would help.
Give a like if you are satisfied.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.