generated from Suvechchhaa/HacktoberFest-DSA2022
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBalanced_Paranthesis.c
77 lines (57 loc) · 1.1 KB
/
Balanced_Paranthesis.c
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 <stdio.h>
#include <stdlib.h>
#define MAXSIZE 50
struct lifo{
char x[MAXSIZE];
int top;
};
typedef struct lifo stack;
stack s;
void createStack(stack *s){
s->top = -1;
}
void push(stack *s,char a){
if(s->top == MAXSIZE-1){
printf("\nThe Stack is Full");
exit(-1);
}
else{
s->x[s->top + 1]='a';
s->top++;
}
}
char pop(stack *s){
if(s->top = -1){
printf("\nUNDERFLOW");
}
else{
return s->x[s->top];
}
}
void Balanced(stack *s){
}
void isEmpty(stack *s){
}
int main(){
stack bp;
char str[MAXSIZE];
printf("\nEnter the expression : ");
scanf("%s",str);
createStack(&bp);
for(int i=0;i<(MAXSIZE-1);i++){
if(str[i]=='(' || str[i]=='{' || str[i]=='['){
push(&bp,str[i]);
}
else if(str[i]==')' || str[i]=='}' || str[i]==']'){
if(str[i]== bp.x[bp.top]){
pop(&bp);
}
else{
printf("\nWrong Input");
break;
}
}
}
printf("\nThe Expression is not balanced");
return 0;
}