int evl(char *postfix) { int i=0,x1,x2,r=0; for(i=strlen(postfix); i>=0;i--) { if(isOperand(postfix[i])) push(postfix[i]-'0'); else { x1=pop(); x2=pop(); switch(postfix[i]) { case '+':r=x1+x2;break; case '-':r=x1-x2;break; case '*':r=x1*x2;break; case '/':r=x1/x2;break; } push(r); } } return pop(); } int main() { char *postfix="+2/62"; printf("%d",evl(postfix)); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter