-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.PARENTESIS.cpp
103 lines (92 loc) · 1.48 KB
/
7.PARENTESIS.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
97
98
99
100
101
102
103
//signs brackets ''
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class stackp
{
private:
char s[50];
char infix[50];
int top;
public:
stackp()
{
top=-1;
}
void getdata()
{
cout<<"\n";
fflush(stdin);
cout<<"enter infix exp : ";
cin>>infix;
cout<<"\n";
}
char pop()
{
return(s[top--]);
}
void evaluate()
{
cout<<"\n";
int i;
char op;
top=-1;
for(i=0;infix[i]!='\0';i++)
{
if(infix[i]=='(' || infix[i]=='{' || infix[i]=='[')
{
s[++top]=infix[i];
}
else if(infix[i]==')' || infix[i]=='}' || infix[i]==']')
{
op=pop();
if(op=='('&&infix[i]==')' || op=='{'&&infix[i]=='}' || op=='['&&infix[i]==']')
continue;
else
{
cout<<"Parenthesis does not match";
cout<<"\n";
return;
}
}
}
if(top==-1)
{
cout<<"Parenthesis match";
cout<<"\n";
}
else
{
cout<<"Parenthesis does not match";
cout<<"\n";
}
cout<<"\n";
}
};
main()
{
stackp s1;
int op=-1;
while(op!=0)
{
cout<<"\n\n***VERPISS DICH***"<<endl;
cout<<"1:ENTER INFIX EXP."<<endl;
cout<<"2:EVALUATE"<<endl;
cout<<"3:EXIT"<<endl;
cout<<"ENTER CHOICE : ";
cin>>op;
switch(op)
{
case 1:
s1.getdata();
break;
case 2:
s1.evaluate();
break;
case 3:
op=0;
break;
}
}
}