Doubt related to taking input for Binary Tree


In the above pic, instead of building a tree, sir is taking root as input and in the below pic, sir is giving input.txt as input. What is input.txt and how is it working??

hello @sahilkhan2312000131

here we have overloaded >> operator.
thats why bhaiya is doing
cin>>root; it will build the tree .

that is just a terminal base command, input.txt is file that contains testcase, so what we are is we are taking those test case from input.txt and passing it in bst node distance k program

I have 2 ques:

  1. Once we have overloaded the operator >> for taking input for tree. Then if we want to take input for any other variable say int or char, can we simply use >> operator or we have to do something else??
  2. What test case does input.txt contain? Can you give example??

no we dont have to do anything else.
have u studied polymorphism?

it will contain somthing like this->
4
60 65 50 70
50 65 60 70
2
60 1
65 2

it will contain somthing like this->
4
60 65 50 70
50 65 60 70
2
60 1
65 2
So basically these are inputs for 4 different tress??

no here we have only single tree with 4 nodes.
here is the detail of the input->

ss


Is this the tree which will be formed??
Also why are we giving input like this because in the program we have taken input as level order so for the same tree the input should be like 60 65 70 50 -1 -1 -1 -1 -1 ??

@sahilkhan2312000131
bro have u skipped previous lectures?

there are various method for constructing tree.
here in this problem we are taking help of inordre and preorder to construct the tree

I am getting ur point that there are various methods but for this program we have overloaded the >> operator for level order build() which takes input as lever order that why I am asking why are we taking input as given in .txt file?

oh ok , then bhaiya must be giving level order in input.txt file.

i was sharing this input format from hackerblocks there they are using inorder and preorder.

Also is I want to know that why are we given this:
2
60 1
65 2
as input because we can simply from a BT using Inorder and Preorder traversal.


read this

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.