-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStackParenthesis.c
47 lines (46 loc) · 904 Bytes
/
StackParenthesis.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
//debug this program and learn
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100
char stack[MAX],arr[MAX],x[100];
int top =-1;
void push(char);
void pop(void);
int main()
{
printf("Enter a parenthesized expression\n");
scanf("%s", &arr);
printf("entered string is %s\n",arr);
for (int i = 0 ;arr[i] != '\0' ; i++)
{
switch (arr[i]) {
case '(': push(arr[i]);
break;
case ')': pop();
break;
}
// if(arr[i] == '(')
// push(arr[i]);
// else if(arr[i] == ')')
// pop();
}
if (top == -1)
{
printf("Expression is Valid\n");
}
else
{
printf("Expression is Invalid\n");
}
return 0;
}
void push(char x)
{
top++;
stack[top] = x;
}
void pop()
{
top--;
}