-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbinary-search-tree-insertion.cpp
More file actions
101 lines (81 loc) · 1.54 KB
/
Copy pathbinary-search-tree-insertion.cpp
File metadata and controls
101 lines (81 loc) · 1.54 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include<bits/stdc++.h>
using namespace std;
typedef struct node
{
int data;
node * left;
node * right;
}node;
node * hidden_insert(node* r, int x)
{
if (r == NULL)
{
r = new node;
r->data = x;
r->left = NULL;
r->right = NULL;
}
else
{
if (x < r->data)
{
r->left = hidden_insert(r->left, x);
}
else
{
r->right = hidden_insert(r->right, x);
}
}
return r;
}
void inorder_hidden(node * r)
{
if(r==NULL)
return;
inorder_hidden(r->left);
cout<<r->data<<" ";
inorder_hidden(r->right);
}
#include "binary-search-tree-insertion.hpp"
bool check(node * root1,node * root2)
{
if(root1==NULL && root2==NULL)
return true;
if(root1==NULL)
return false;
if(root2==NULL)
return false;
if(root1->data!=root2->data)
return false;
return (check(root1->left,root2->left) && check(root1->right,root2->right));
}
int main()
{
int n;
cin>>n;
node * root=NULL;
node * root2=NULL;
for(int i=0;i<n;i++)
{
int v1;
cin>>v1;
root=hidden_insert(root,v1);
root2=hidden_insert(root2,v1);
}
int ins_value;
cin>>ins_value;
root=insert(root,ins_value);
root2=hidden_insert(root2,ins_value);
string S="Some possible errors:\n1. You returned a NULL value from the function. \n2. There is a problem with your logic\n3. You are printing some value from the function ";
if(check(root,root2))
{
cout<<"Right Answer!\n";
}
else
{
cout<<"Wrong Answer!\n";
cout<<S<<endl;
}
//norder_hidden(root);
//cout<<endl;
}