-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpression.cpp
More file actions
40 lines (39 loc) · 811 Bytes
/
expression.cpp
File metadata and controls
40 lines (39 loc) · 811 Bytes
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
#include<bits/stdc++.h>
using namespace std;
struct node{
char data;
node* left;
node* right;
node(char dta){
data= dta;
left = NULL;
right = NULL;
}
}* root=NULL;
char ch[20];
void display(node* root){
if(root!=NULL){
display(root->left);
cout<<root->data<<" ";
display(root->left);
}
}
node* convert(node* root,char ptr){
if(isalpha(ptr)) return new node(ptr);
if(root == NULL){
node* nn = new node(ptr);
root = nn;
}
root->left= convert(root->left,ptr++);
root->right= convert(root->right,ptr++);
return root;
}
int main(){
cout<<"exp ";
cin>>ch;
convert(root,ch[20]);
// node*k ;
// k = convert(root,st[0]);
display(root);
return 0;
}