-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperator_balance.cpp
More file actions
41 lines (39 loc) · 846 Bytes
/
operator_balance.cpp
File metadata and controls
41 lines (39 loc) · 846 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
41
#include<iostream>
using namespace std;
char ar[5];
int top = 0;
int n=5;
char value;
int push(char element){
if(top<n){
ar[top] = element;
top = top+1;
cout<<"push successful"<<endl;
}
else{
cout<<"Stack overflow"<<endl;
}
}
int pop(){
if(top>0){
top = top-1;
value = ar[top];
cout<<"Pop succesful "<<value<< endl;
}
else { cout<<" empty"<<endl;}
}
int main(){
int ts = (int)'[';
int tc = (int)']';
int ss = (int)'{';
int sc = (int)'}';
int fs = (int)'(';
int fc = (int)')';
string expression = "[({})]";
for(int i=0; i<5; i++){
if((int)expression[i] == ts || ss || fs ){
push(expression[i]);
}
else{ pop();}
}
}