-
Notifications
You must be signed in to change notification settings - Fork 0
/
BSTJULY.CPP
84 lines (59 loc) · 1.19 KB
/
BSTJULY.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<bits/stdc++.h>
using namespace std;
struct node{
int data;
struct node*left;
struct node*right;
};
void create(struct node **root,int data)
{
struct node*temp;
if(*(root)==NULL)
{
//cout<<"i worked root ";
temp=(struct node*)malloc(sizeof(struct node));
temp->data=data;
temp->right=NULL;
temp->left=NULL;
*(root)=temp;
}
else if(data<(*root)->data)
{
//cout<<"i worked leftt";
create(&(*root)->left,data);
}
else{
//cout<<"i worked left ";
create(&(*root)->right,data);
}
return ;
}
void inorder(struct node* root)
{
if(root!=NULL)
{
inorder(root->left);
cout<<root->data;
inorder(root->right);
}
}
int main()
{
struct node*root=NULL;
if(root==NULL)
{
// cout<<"rootNULL";
}
create(&root,10);
//cout<<root->data;
create(&root,15);
create(&root,6);//
//cout<<root->right->data;
//cout<<root->right->right->data;
create(&root,5);
//cout<<root->left->data;
inorder(root);
if(root->left==NULL)
cout<<"NULL";
return 0 ;
}