-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlec7_1.cpp
More file actions
49 lines (45 loc) · 895 Bytes
/
lec7_1.cpp
File metadata and controls
49 lines (45 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
#include<queue>
using namespace std;
class Node
{
public:
int data;
Node* left;
Node* right;
Node(int val)
{
data = val;
left = NULL;
right = NULL;
}
};
int main(){
queue<Node*> q;
int x;
cout<<"Enter the value of root"<<endl;
cin>>x;
Node* root = new Node(x);
q.push(root);
int first , second;
while(!q.empty())
{
Node* temp = q.front();
q.pop();
cout<<"Enter the left child of "<<temp->data<<endl;
cin>>first;
if(first!=-1)
{
temp->left = new Node(first);
q.push(temp->left);
}
cout<<"Enter the right child of "<<temp->data<<endl;
cin>>second;
if(second!=-1)
{
temp->right = new Node(second);
q.push(temp->right);
}
}
return 0;
}