Week 6 - Group 17 CSE - C
Week 6 - Group 17 CSE - C
Week 6 - Group 17 CSE - C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
// Stack structure
typedef struct {
char array[MAX_SIZE];
int top;
} Stack;
s->top = -1;
if (!isFull(s))
s->array[++(s->top)] = c;
else
printf("Stack overflow\n");
if (!isEmpty(s))
return s->array[(s->top)--];
else {
printf("Stack underflow\n");
return '\0';
if (!isEmpty(s))
return s->array[s->top];
else {
printf("Stack is empty\n");
return '\0';
switch (op) {
case '+':
case '-':
return 1;
case '*':
case '/':
return 2;
default:
return 0;
Stack stack;
initializeStack(&stack);
int j = 0;
char c = infix[i];
if (isalnum(c))
postfix[j++] = c;
else if (c == '(')
push(&stack, c);
else if (c == ')') {
postfix[j++] = pop(&stack);
} else {
postfix[j++] = pop(&stack);
push(&stack, c);
while (!isEmpty(&stack))
postfix[j++] = pop(&stack);
postfix[j] = '\0';
int main() {
char infix[MAX_SIZE];
char postfix[MAX_SIZE];
infixToPostfix(infix, postfix);
return 0;