find the mistake plzzzzzz | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

find the mistake plzzzzzz

#include<stdio.h> #include<stdlib.h> #include<conio.h> struct stack { int top; int size; char *arr; }; int isFull(struct stack *sp) { if(sp->top==sp->size-1) { return 1; } else{ return 0; } } int isEmpty(struct stack *sp) { if(sp->top==-1) { return 1; } return 0; } void push(struct stack *sp,char val) { sp->top++; sp->arr[sp->top]=val; } char pop(struct stack *sp) { char r=sp->arr[sp->top]; sp->top--; return r; } int isEqual(char a,char b) { if(a=='(' && b==')') { return 1; } if(a=='[' && b==']') { return 1; } if(a=='{' && b=='}') { return 1; } return 0; } int match(char *ex) { struct stack *sp=(struct stack*)malloc(sizeof(struct stack)); sp->size=100; sp->top=-1; sp->arr=(char*)malloc(sp->size * sizeof(char)); char pop_val; for(int i=0; ex[i]!='\0'; i++) { if(ex[i]== '{' || ex[i]== '[' || ex[i]== '(') { if(isFull(sp)) { return 0; } else { push(sp,ex[i]); } } else if(ex[i]== '}' || ex[i]== ']' || ex[i]== ')') { if(isEmpty(sp)) { return 0; } pop_val = pop(sp); if(isEqual(pop_val,ex[i])) { return 1; } else { return 0; } } } if(isEmpty(sp)) { return 1; } else { return 0; } } int main() { char *ex = "[4-6](((8){(9-8)})"; if(match(ex)) { printf("true \n"); } else { printf("false \n"); } return 0; }

19th Dec 2020, 11:11 AM
Dershil Jadav
Dershil Jadav - avatar
2 Answers
0
No problem
21st Dec 2020, 12:03 PM
Dedipyaman Bhattacharjee
Dedipyaman Bhattacharjee - avatar
0
It is working
21st Dec 2020, 12:03 PM
Dedipyaman Bhattacharjee
Dedipyaman Bhattacharjee - avatar