DSA02-postfixevaluation
DSA02-postfixevaluation
INSTITUTE OF TECHNOLOGY
DHULE (M.S.)
DEPARMENT OF COMPUTER ENGINEERING
Remark
Subject : Data Syructure Lab
#include <stdio.h>
#include <stdlib.h>
int stack[STACKSIZE];
int top = -1;
void push(int x)
{
int pop()
{
int y;
if (top < 0) {
printf("stack under flow");
}
else {
y = stack[top];
top = top - 1;
return y;
}
}
int i;
char ch;
int C;
int A, B;
push(ch - '0');
}
else if (ch == '+' || ch == '-' || ch == '*' || ch == '/') {
A = pop();
B = pop();
switch (ch)
{
case '*':
C = B * A;
break;
case '/':
C = B / A;
break;
case '+':
C = B + A;
break;
case '-':
C = B - A;
break;
}
push(C);
}
}
printf(" \n The Ans is : %d \n", pop());
}
int main()
{
int i;
char postfix[ARRYSIZE];
printf("Enter postfix experssion and also enter opening and
closing brackets.\n");
for (i = 0; i <= ARRYSIZE - 1; i++) {
scanf("%c", &postfix[i]);
if (postfix[i] == ')')
{
break;
}
}
EvaluatePostfix(postfix);
return 0;
}
Output: