int evl(char *postfix) { int i=0,x1,x2,r=0; for(i=0;postfix[i]!='\0';i++) { if(isOperand(postfix[i])) push(postfix[i]-'0'); else { x2=pop(); x1=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="234*+82/-"; 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