Skip to content

Commit d655b40

Browse files
Create Balancing_Parenthesis_using_stack.c
1 parent 7c858e5 commit d655b40

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Balancing_Parenthesis_using_stack.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// To evaluate the expression, the parenthesis need to be balanced which means all open parenthesis should have a closed parenthesis. Write a program using stack data structure to check whether the given parenthesis string is balanced or not.
2+
3+
// Input: String with parenthesis
4+
5+
// Output: String is “Balanced” or “Not Balanced”
6+
7+
#include<stdio.h>
8+
#include<string.h>
9+
int top=-1;
10+
char s[100];
11+
void push(char e)
12+
{
13+
top++;
14+
s[top]=e;
15+
}
16+
int main()
17+
{
18+
char ch[100];
19+
int flag;
20+
scanf("%s",ch);
21+
for(int i=3;i<strlen(ch)-3;i++)
22+
push(ch[i]);
23+
for(int i=0,j=top;i<=top;i++,j--)
24+
{
25+
if(ch[i]==ch[j])
26+
{
27+
flag=1;
28+
printf("Not Balanced");
29+
break;
30+
}
31+
}
32+
if(flag!=1)
33+
printf("Balanced");
34+
}

0 commit comments

Comments
 (0)