0

find the misstake plz......

#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, 7:00 AM
Dershil Jadav
Dershil Jadav - avatar
1 Antwort
+ 2
I'd remove the conio.h header but otherwise I can't tell what the program is doing wrong. Also please don't paste your code into the question but create a private code in the playground and link it using the plus button :)
19th Dec 2020, 7:42 AM
Aaron Eberhardt
Aaron Eberhardt - avatar