EXp 3
EXp 3
char a[MAX];
int top = -1;
int main() {
char inf[MAX], post[MAX];
printf("Enter elements of infix:");
scanf("%s", inf);
InfToPost(inf, post);
printf("Postfix expression:");
puts(post);
return 0;
}
strcpy(t, "");
while (s[i] != '\0') {
if (s[i] == '(') {
push(a, s[i]);
i++;
}
else if (s[i] == ')') {
while (top != -1 && a[top] != '(') {
t[j] = pop(a);
j++;
}
if (top == -1) {
printf("INCORRECT EXPRESSION");
exit(1);
}
}
else if (isdigit(s[i]) || isalpha(s[i])) {
t[j] = s[i];
j++;
i++;
}
else if (s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/'
|| s[i] == '%') {
while (top != -1 && a[top] != '(' && priority(a[top]) >=
priority(s[i])) {
t[j] = pop(a);
j++;
}
push(a, s[i]);
i++;
}
else {
printf("Incorrect element in expression");
exit(1);
}
}
while (top != -1 && a[top] != '(') {
t[j] = pop(a);
j++;
}
t[j] = '\0';
}