-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxCy.c
105 lines (86 loc) · 1.1 KB
/
xCy.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include<stdio.h>
# define size 100
typedef struct stack{
int top;
int a[size];
}Stack;
void init(Stack *p)
{
p->top=-1;
}
void push(Stack *p,int v)
{
if(p->top == size-1)
{
printf("stack is full\n");
return 0;
}
else{
p->top+=1;
p->a[p->top]=v;
}
}
int pop(Stack *p){
if(p->top == -1){
printf("stack is empty\n");
return 0;
}
else{
return p->a[p->top--];
}
}
char peek(Stack *p)
{
if(p->top == -1)
return '/0';
else{
return p->a[p->top];
}
}
int empty(Stack *p)
{
if(p->top == -1)
return 1;
else
return 0;
}
int check(char a, char b)
{
if(a==b)
return 1;
else
return 0;
}
int main()
{
Stack s;
char b[100];
init(&s);
int i,j,flag=1;
char t;
printf("enter the expression\n");
scanf("%s",b);
for(i=0;b[i] != 'C';i++)
{
push(&s,b[i]);
}
i++;
while(b[i] != '\0')
{
t=pop(&s);
if(b[i] != t){
flag=1;
break;
}
else
{
flag=0;
}
i++;
}
if(!flag)
printf("valid\n");
else
printf("not valid\n");
return 0;
}