Conversion of infix expression to postfix expression

include <stdio.h>
include <stdlib.h>
include <string.h>
include <ctype.h>

define MAX_SIZE 100

struct Stack {
int top;
unsigned capacity;
char* array;
};

struct Stack* createStack(unsigned capacity) {
struct Stack* stack = (struct Stack*)malloc(sizeof(struct Stack));
stack->top = -1;
stack->capacity = capacity;
stack->array = (char*)malloc(stack->capacity * sizeof(char));
return stack;
}

int isEmpty(struct Stack* stack) {
return stack->top == -1;
}

char peek(struct Stack* stack) {
return stack->array[stack->top];
}

void push(struct Stack* stack, char item) {
stack->array[++stack->top] = item;
}

char pop(struct Stack* stack) {
if (!isEmpty(stack))
return stack->array[stack->top–];
return ‘$’; // Should never happen for valid expressions
}

int precedence(char ch) {
if (ch == ‘+’ || ch == ‘-’) return 1;
if (ch == ‘*’ || ch == ‘/’) return 2;
return 0;
}

int isOperator(char ch) {
return (ch == ‘+’ || ch == ‘-’ || ch == ‘*’ || ch == ‘/’);
}

int main() {
int n;
scanf(“%d”, &n);

char infix[MAX_SIZE];
scanf("%s", infix);

char postfix[MAX_SIZE];
int k = 0;

struct Stack* stack = createStack(n);

for (int i = 0; i < n; i++) {
    char ch = infix[i];

    if (isalnum(ch)) {
        postfix[k++] = ch;
    }
    else if (ch == '(') {
        push(stack, ch);
    }
    else if (ch == ')') {
        while (!isEmpty(stack) && peek(stack) != '(')
            postfix[k++] = pop(stack);
        pop(stack);
    }
    else if (isOperator(ch)) {
        while (!isEmpty(stack) && precedence(peek(stack)) >= precedence(ch))
            postfix[k++] = pop(stack);
        push(stack, ch);
    }
}

while (!isEmpty(stack))
    postfix[k++] = pop(stack);

postfix[k] = '\0';

printf("%s", postfix);

return 0;

}