Evaluation of Postfix Expression
Evaluation of Postfix Expression
#include<stdio.h>
#define max 40
if(isfull(sptr))
{
printf("stack is full\n");
}
else{
sptr->top++;
sptr->list[sptr->top]=item;
printf("\n%d is pushed",item);
}
}
if(isempty(sptr))
{
return -99999;
}
else
{
temp=sptr->list[sptr->top];
sptr->top--;
printf("\n%d is popped",temp);
return temp;
}
}
int isoperand(char op)
{
if(op >='A'&& op <='Z' ||op >='a' && op <='z' )
return 1;
else
return 0;
}
int isoperator(char op)
{
if(op == '+' || op =='-' || op== '*' || op == '/' || op == '%' )
return 1;
else
return 0;
}
while(str1[i]!='\0')
{
if(isoperand(str1[i]))
{
printf("enter the value of %c",str1[i]);
scanf("%d",&v);
push(&s,v);
i++;
}
else if(isoperator(str1[i]))
{
op=str1[i];
op1=pop(&s);
op2=pop(&s);
result=calculate(op1,op,op2);printf("result =%d",result);
push(&s,result);
i=i+1;
}
else
return 0;
}
result=pop(&s);
printf("result::%d\n",result);