forked from kevinbhingaradiya/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack_parenthesis.cpp
More file actions
77 lines (60 loc) · 1.21 KB
/
stack_parenthesis.cpp
File metadata and controls
77 lines (60 loc) · 1.21 KB
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
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
struct stack{
int top;
int size;
char *arr;
};
int empty(struct stack*s){
if(s->top==-1)
{
return 1;
}
else{
return 0;
}
}
int full(struct stack*s){
if(s->top==s->size-1){
return 1;
}else{
return 0;
}
}
void push(struct stack*s,char v){
if(full(s)){cout<<"Stack overflow!!!!!!!"<<endl;}
else{
s->top++;
s->arr[s->top]=v;
cout<<v<<" is pushed!!"<<endl;
}
}
void pop(struct stack*s){
if (empty(s)){cout<<"Stack underflow!!!!!!!"<<endl;}
else{
char temp =s->arr[s->top];
s->top--;
cout<<temp<<" is poped up!!"<<endl;
}
}
int main(){
stack*s=new stack;
s=new stack;
s->top=-1;
s->size=10;
s->arr=(char *)malloc(s->size*sizeof(char));
char*v="{{{{{{}}}}}}";
for(int i=0;i<strlen(v);i++){
if(v[i]=='{'||v[i]=='('||v[i]=='['){
push(s,v[i]);
}
if(v[i]=='}'||v[i]==']'||v[i]==')'){
pop(s);
}
}
if(empty(s)){
cout<<"balanced"<<endl;
}else{cout<<"unbalanced"<<endl;}
}