-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentical_bst.cpp
More file actions
50 lines (43 loc) · 822 Bytes
/
identical_bst.cpp
File metadata and controls
50 lines (43 loc) · 822 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
50
#include <iostream>
using namespace std;
class Node{
public:
int data;
Node *left,*right;
Node(int val){
data=val;
left=right=NULL;
}
};
bool isIdentical(Node *root1,Node *root2){
if(root1==NULL && root2==NULL){
return true;
}
else if(root1==NULL || root2==NULL){
return false;
}
else{
bool cond1=root1->data==root2->data;
bool cond2=isIdentical(root1->left,root2->left);
bool cond3=isIdentical(root1->right,root2->right);
if(cond1 && cond2 && cond3){
return true;
}
return false;
}
}
int main(){
Node *root=new Node(2);
root->left=new Node(1);
root->left=new Node(3);
Node *root1=new Node(2);
root1->left=new Node(1);
root1->left=new Node(4);
if(isIdentical(root,root1))
{
cout<<"It is Identical"<<endl;
}else{
cout<<"It is not Identical"<<endl;
}
return 0;
}