-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckifleaftraversalissame.cpp
More file actions
64 lines (54 loc) · 1.42 KB
/
checkifleaftraversalissame.cpp
File metadata and controls
64 lines (54 loc) · 1.42 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <bits/stdc++.h>
using namespace std;
class BinaryTree
{
public:
int value;
BinaryTree*left;
BinaryTree*right;
BinaryTree(int value){
this->value = value;
left = nullptr;
right = nullptr;
}
};
void recursive1(vector<int>tree1,BinaryTree*root1)
{
if(root == NULL)
{
return;
}
if(root->left == NULL && root->right == NULL)
{
tree1.push_back(root->val);
}
recursive(tree1,root1->left);
recursive(tree1,root1->right);
}
bool compareLeafTraversal(BinaryTree*root1,BinaryTree*root2)
{
vector<int>tree1;
vector<int>tree2;
recursive1(tree1,root1);
recursive2(tree2,root2);
}
int main()
{
BinaryTree*root1 = new BinaryTree(1);
root->left = new BinaryTree(2);
root->right = new BinaryTree(3);
root->left->left = new BinaryTree(4);
root->left->right = new BinaryTree(5);
root->right->right = new BinaryTree(6);
root->left->right->left = new BinaryTree(7);
root->left->right->right = new BinaryTree(8);
BinaryTree*root2 = new BinaryTree(1);
root->left = new BinaryTree(2);
root->right = new BinaryTree(3);
root->left->left = new BinaryTree(4);
root->left->right = new BinaryTree(7);
root->right->right = new BinaryTree(5);
root->right->right->left = new BinaryTree(8);
root->right->right->right = new BinaryTree(6);
compareLeafTraversal(root1,root2);
}