Dsa Expt 8 123a3007
Dsa Expt 8 123a3007
Dsa Expt 8 123a3007
Code :
#include <stdio.h>
#include <string.h>
// Stack structure
char stack[MAX];
DSA EXPT 8 NAME- SIDDHESH BAGDE PRN : 123A3007
// Stack operations
void push(char x) {
if (top == MAX - 1) {
printf("Stack Overflow\n");
} else {
stack[++top] = x;
char pop() {
if (top == -1) {
printf("Stack Underflow\n");
return -1;
} else {
return stack[top--];
int precedence(char x) {
if (x == '+' || x == '-') {
return 0; // Non-operator
DSA EXPT 8 NAME- SIDDHESH BAGDE PRN : 123A3007
int i = 0, j = 0;
char ch;
ch = infix[i];
if (isalnum(ch)) {
postfix[j++] = ch;
push(ch);
postfix[j++] = pop();
else {
postfix[j++] = pop();
push(ch);
i++;
postfix[j++] = pop();
int stack[MAX];
int i = 0;
char ch;
ch = postfix[i];
if (isdigit(ch)) {
else {
switch (ch) {
i++;
int main() {
scanf("%s", infix);
infixToPostfix(infix, postfix);
return 0;
Output :
Enter an infix expression: A+B*(C-D)
Result of evaluation: 0