#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAX 100
struct Stack {
    char arr[MAX];
    int top;
};
void initStack(struct Stack *s){
    s->top=-1;
}
int isEmpty(struct Stack*s){
    return s->top == -1;
}
void push(struct Stack *s,char value){
    if (s->top < MAX -1){
        s->arr[++(s->top)] = value;
    }
}
char pop(struct Stack*s) {
    if (!isEmpty(s)) {
        return s->arr[(s->top)--];
    }
    return -1;
}
char peek(struct Stack *s){
    if (!isEmpty(s)){
        return s->arr[s->top];
    }
    return -1;
}
int precedence (char c){
    if (c=='+'||c=='-'){
        return 1;
    }
    if (c=='*' ||c =='/') {
        return 2;
    }
    return 0;
}
int isOperand(char c){
    return isalpha(c);
}
void infixtopostfix(char *infix, char *postfix) {
    struct Stack s;
    initStack(&s);
    
    int j=0;
    for (int i=0;i<strlen(infix);i++){
        char c = infix[i];
        if (isOperand(c)) {
            postfix[j++] = c;
        }
        else if (c== '('){
            push(&s, c);
        }
        else if (c== ')') {
            while (!isEmpty(&s) && peek(&s) !='(') {
                postfix[j++]=pop(&s);
            }
            pop(&s);
        }
        else if (c == '+' || c =='-' || c=='*' || c=='/') {
            while (!isEmpty(&s) && precedence(peek(&s)) >=precedence(c)) {
                postfix[j++] = pop(&s);
        }
        postfix[j]='\0';
    }
    int main() {
        char infix[MAX];
        char postfix[MAX];
        printf("Enter infix expression:");
        scanf("%s",infix);
        infixToPostfix(infix, postfix);
        printf("Postfix expression: %s\n",postfix)
    }