-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpostfixevaluation.cpp
96 lines (94 loc) · 1.47 KB
/
postfixevaluation.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
85
86
87
88
89
90
91
92
93
94
95
96
//program to implement a binary search tree or searching
#include<stdio.h>
#include<stdlib.h>
struct BST
{
int data;
struct BST *left,*right;
}*root=NULL;
typedef struct BST node;
node* createNode(data)
{
node *newnode;
newnode=(node*)malloc(sizeof(node));
newnode->data=data;
newnode->left=newnode->right=NULL;
return newnode;
}
node* insertNode(node* root,int n)
{
if(root==NULL)
{
root=createNode(n);
}
else if(n<=root->data)
{
root->left=insertNode(root->left,n);
}
else
{
root->right=insertNode(root->right,n);
}
}
int search(node* root,int number)
{
if(root==NULL)
{
return 0;
}
else if(number==root->data)
{
return 1;
}
else if(number<=root->data)
{
return search(root->left,number);
}
else
{
return search(root->right,number);
}
}
void display(node* root)
{
if(root!=NULL)
{
display(root->left);
printf("%d\n",root->data);
display(root->right);
}
}
int main()
{
int n,value,number;
char ch;
while(1)
{
printf("1=Insert 2=Search 3=Display 4=Exit\n");
printf("Enter the value\n");
scanf("%d",&value);
switch(value)
{
case 1:
printf("Enter your number to be insert : ");
scanf("%d",&n);
root=insertNode(root,n);
break;
case 2:
printf("Enter the number\n");
scanf("%d",&number);
if(search(root,number)==1)
printf("Item is found Search is successful\n");
else
printf("Item is found Search is successful\n");
break;
case 3:
display(root);
break;
case 4:
exit(0);
default :printf("Please Enter correct value\n");
break;
}
}
}