-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic _tree_operations.cpp
More file actions
90 lines (78 loc) · 1.65 KB
/
basic _tree_operations.cpp
File metadata and controls
90 lines (78 loc) · 1.65 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
#include<iostream>
using namespace std;
struct node{
node * left;
node * right;
int val;
};
struct node * root=NULL;
void insert(void){
int data;
cout<<"insertion value :";
cin>>data;
struct node * node1=new node;
struct node * temp=root;
struct node * ptr=NULL;
node1->left=NULL;
node1->right=NULL;
node1->val=data;
if(root==NULL){
root=node1;
}
else{
while(temp!=NULL && temp->val!=data){
ptr=temp;
if(data < temp->val){
temp=temp->left;
}
else{
temp=temp->right;
}
}
if(temp!=NULL){
cout<<"value already present";
}
if(data< ptr->val){
ptr->left=node1;
}
else{
ptr->right=node1;
}
}
}
void remove(void){}
void inorder(struct node * root){}
void preorder(struct node * root){}
void postorder(struct node * root){}
int main(){
int n;
cout<<"enter choice 1.insert 2.delete 3.inorder 4.preorder 5.postorder ";
cin>>n;
if(n==1) insert();
else if(n==2) remove();
else if(n==3) {
if(root==NULL){
cout<<"empty";
}
else{
inorder(root);
}
}
else if(n==4) {
if(root==NULL){
cout<<"empty";
}
else{
preorder(root);
}
}
else if(n==5) {
if(root==NULL){
cout<<"empty";
}
else{
postorder(root);
}
}
return 0;
}