-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathass_4.cpp
83 lines (70 loc) · 1.98 KB
/
ass_4.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
#include <iostream>
using namespace std;
#define size 10
class stackexp{
int top;
char stk[size];
public:
stackexp(){
top=-1;
}
void push(char);
char pop ();
int isfull();
int isempty();
};
void stackexp::push(char x){
top = top+1;
stk[top] = x;
}
char stackexp::pop(){
char s;
s = stk[top];
top = top-1;
return s;
}
int stackexp::isfull(){
if(top == size)
return 1;
else
return 0;
}
int stackexp::isempty(){
if(top == -1)
return 1;
else
return 0;
}
int main(){
stackexp s1;
char exp[20], ch;
int i=0 ;
cout<<"\n\t!!Parenthesis checker.....!!!!"<<endl;
cout <<"\n Enter the expression to check whether it is in well form or not : "<<endl;
cin>>exp;
if((exp[0]==')')||(exp[0]==']')||(exp[0]=='}')){
cout<<"\n Invail Expression .......\n";
return 0;
}
else{
while (exp[i]!='\0'){
ch = exp[i];
switch(ch){
case '(':s1.push(ch);break;
case '[':s1.push(ch);break;
case '{':s1.push(ch);break;
case ')':s1.pop();break;
case ']':s1.pop();break;
case '}':s1.pop();break;
}
i = i +1;
}
}
if(s1.isempty()){
cout<<"\n The expression is well Parameterized...\n";
}
else{
cout<<"\n sorry.....! The Expression is not well parameterised....\n";
}
return 0 ;
}