Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Write program that converts an infix expression into an equivalent postfix expression

Write program that converts an infix expression into an equivalent postfix expression

Computer Science

Write program that converts an infix expression into an equivalent postfix expression. 

The rules to convert an infix expression into an equivalent postfix expression are as follows:

Suppose infx represents the infix expression and pfx represents the postfix expression. The rules to convert infx into pfx are as follows:

a. Initialize pfx to an empty expression and also initialize the stack.

b. Get the next symbol, sym, from infx.

 b.1. If sym is an operand, append sym to pfx.

b.2. If sym is (, push sym into the stack.

b.3. If sym is ), pop and append all the symbols from the stack until the

most recent left parenthesis. Pop and discard the left parenthesis.

b.4. If sym is an operator:

b.4.1. Pop and append all the operators from the stack to pfx that are above the most recent left parenthesis and have precedence greater than or equal to sym.

b.4.2. Push sym onto the stack.

c. After processing infx, some operators might be left in the stack. Pop and append to pfx everything from the stack.

In this program, you will consider the following (binary) arithmetic operators: +, -, *, and /. You may assume that the expressions you will process are error free.

Design a class that stores the infix and postfix strings. The class must include the following operations:

 • getInfix—Stores the infix expression

• showInfix—Outputs the infix expression

• showPostfix—Outputs the postfix expression

Some other operations that you might need are the following:

convertToPostfix—Converts the infix expression into a postfix

expression. The resulting postfix expression is stored in pfx.

precedence—Determines the precedence between two operators. If the first operator is of higher or equal precedence than the second operator, it returns the value true; otherwise, it returns the value false.

Include the constructors and destructors for automatic initialization and dynamic memory deallocation.

For each expression, your answer must be in the following form:

Infix Expression: 1+ 2 - 4;

Postfix Expression: 12 + 4 -

And then Evaluate the post fix expression and display the solution of postfix expression

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Related Questions