#include <stdio.h>
#include <stdlib.h>
struct stack {
int size;
int top;
char *arr;
};
int isfull(struct stack *ptr) {
return ptr->top == ptr->size - 1;
}
int isempty(struct stack *ptr) {
return ptr->top == -1;
}
void push(struct stack *ptr, char val) {
if (isfull(ptr)) {
printf("Stack is full\n");
} else {
ptr->top++;
ptr->arr[ptr->top] = val;
}
}
char pop(struct stack *ptr) {
if (isempty(ptr)) {
printf("Stack is empty\n");
return '\0'; // Return a default value or handle it appropriately in your context
} else {
char val = ptr->arr[ptr->top];
ptr->top--;
return val;
}
}
int para(char *exp) {
struct stack *sp = (struct stack *)malloc(sizeof(struct stack));
sp->size = 10;
sp->top = -1;
sp->arr = (char *)malloc(sp->size * sizeof(char));
for (int i = 0; exp[i] != '\0'; i++) {
if (exp[i] == '(') {
push(sp, '(');
} else if (exp[i] == ')') {
if (isempty(sp)) {
return 0;
} else {
pop(sp);
}
}
}
if (isempty(sp)) {
return 1;
} else {
return 0;
}
}
int main() {
char *exp = "7(7+)";
if (para(exp)) {
printf("Parenthesis matching\n");
} else {
printf("Parenthesis is not matching\n");
}
return 0;
}
why this code is not working on replit