-
Notifications
You must be signed in to change notification settings - Fork 0
/
VALIDBIN.CPP
84 lines (73 loc) · 1.53 KB
/
VALIDBIN.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
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
#include<iostream.h>
#include<conio.h>
struct Node
{
int data;
Node* left;
Node* right;
};
Node* new_node(int x)
{
Node* new_node = new Node();
new_node->data = x;
new_node->left=NULL;
new_node->right=NULL;
return new_node;
}
Node* insert(Node* root , int data)
{
if(root==NULL)
{
return new_node(data);
}
else
{
if(data<root->data)
root->left = insert(root->left,data);
else
root->right=insert(root->right,data);
}
return (root);
}
int check(Node*root)
{
int min=root->left->data;
int max=root->right->data;
if(root==NULL || root->left == NULL ||root->right==NULL )
return 1;
if(min < root->data && max > root->data)
{
return (check(root->left)&& check(root->right));
}
else
{
return 0;
}
}
void validate(Node * root)
{
int a;
a=check(root);
cout<<a;
// cout<<root->data;
// cout<<"\nPrimary Root Left Data\n "<<root->left->data;
// cout<<"\n Primary Root Right Data\n"<<root->right->data;
// root=root->right;
// cout<<"\nRight Root Traversal\n";
// cout<<"\nRight Node LEft Data\n"<<root->left->data;
// cout<<"\nRight Root Right Data\n"<<root->right->data;
}
void main()
{
clrscr();
Node* root = NULL;
root=insert(root,5);
insert(root,3);
insert(root,1);
insert(root,4);
insert(root,7);
insert(root,6);
insert(root,9);
validate(root);
getch();
}