Evaluating infix arithmetic expressions with two stacks C++ implementation

Here, I provide a C++ implementation of a console – based calculator. Basically, it reads in infix arithmetic expressions and produces the result of their evaluation.

I made the simplifying assumption that tokens in the input expression are separated by spaces in order to simplify tokenization. The evaluation of expressions is done with two stacks, one for operands and the other for operators. The program combines the algorithms for infix-to-postfix conversion and postfix evaluation, eliminates the production of intermediate postfix expression and requires just one scan of the input infix expression.

Take a look at the C++ implementation.

Try your hand at problem ARTHEVAL that uses this idea.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s