-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_tree.cpp
More file actions
34 lines (28 loc) · 841 Bytes
/
Copy pathbinary_tree.cpp
File metadata and controls
34 lines (28 loc) · 841 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
#include<iostream>
using namespace std;
struct Node
{
int data;
struct Node* left;
struct Node* right;
Node(int val)
{
data = val;
left = NULL;
right = NULL;
}
};
int main()
{
struct Node* root = new Node(1);
root->left = new Node(2);
root->right = new Node(3);
root->left->left = new Node(4);
root->left->right = new Node(5);
cout << root->data << endl;
cout << root->data << " " << root->left->data << endl;
cout << root->data << " " << root->left->data << " " <<root->right->data << endl;
cout << root->data << " " << root->left->data << " " <<root->right->data <<" " << root->left->left->data << endl;
cout << root->data << " " << root->left->data << " " <<root->right->data <<" " << root->left->right->data << endl;
return 0;
}