-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18TwoTreeIdentical.cpp
44 lines (35 loc) · 1.01 KB
/
18TwoTreeIdentical.cpp
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
#include <bits/stdc++.h>
using namespace std;
struct TreeNode
{
int data;
struct TreeNode* left;
struct TreeNode* right;
TreeNode(int val)
{
data = val;
left = NULL;
right = NULL;
}
};
bool equalTree(TreeNode* p,TreeNode* q){
if(p==NULL || q==NULL){
return (p==q);
}
return (p->data==q->data)&&(equalTree(p->left,q->left))&&(equalTree(p->right,q->right));
}
int main(){
struct TreeNode* root = new TreeNode(2);
root->left = new TreeNode(5);
root->left->left = new TreeNode(4);
root->left->left->left = new TreeNode(3);
root->left->left->right = new TreeNode(2);
root->left->right = new TreeNode(5);
root->right = new TreeNode(7);
root->right->left = new TreeNode(9);
root->right->left->right = new TreeNode(2);
root->right->left->right->right = new TreeNode(4);
root->right->left->right->left = new TreeNode(1);
root->right->left->left = new TreeNode(3);
root->right->right = new TreeNode(7);
}