-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinflixvalidation.c
62 lines (60 loc) · 991 Bytes
/
inflixvalidation.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
#include<stdio.h>
#include<stdlib.h>
int top = -1;
char stack[100];
void push(char a)
{
top++;
stack[top] = a;
}
void pop()
{
if (top == -1)
{
printf("Expression is Empty.\n");
exit(0);
}
else
{
top--;
}
}
int main()
{
int i;
char a[100];
printf("\nEnter an Expression : ");
scanf("%s",a);
for (i = 0; a[i] != '\0';i++)
{
if (a[i] == '(')
{
push(a[i]);
}
else if (a[i] == '{')
{
push(a[i]);
}
else if (a[i] == '[')
{
push(a[i]);
}
else if (a[i] == ')')
{
pop();
}
else if (a[i] == '}')
{
pop();
}
else if (a[i] == ']')
{
pop();
}
}
if (top == -1)
printf("Expression is Valid.\n");
else
printf("Expression is Invalid.\n");
return 0;
}