forked from pranav-nb/Hacktoberfest22
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinaryTree.cpp
62 lines (54 loc) · 1.11 KB
/
binaryTree.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
#include<iostream>
using namespace std;
class sll
{
struct node
{
int data;
node *left;
node *right;
};
public:
sll()
{
node *root=NULL;
// cout<<"object created"<<endl;
}
node *root;
node* insertion(node* root,int n)
{
if(root==NULL)
{
node *t=new node;
t->data=n;
t->left=NULL;
t->right=NULL;
return t;
}
else if(n<=root->data)
{
root->left=insertion(root->left,n);
}
else{
root->right=insertion(root->right,n);
}
return root;
}
void display(node *root)
{
if(root!=NULL){
display(root->left);
cout<<root->data<<"/t"<<endl;
display(root->right);
}
}
};
int main()
{
sll binary;
binary.root=binary.insertion(binary.root,10);
binary.root=binary.insertion(binary.root,30);
binary.root=binary.insertion(binary.root,30);
binary.display(binary.root);
return 0;
}