# Infix to Postfix Converter Using Stacks and Queues

Problem

You will implement an algorithm that employs a stack and queue to convert infix expressions to postfix and then evaluate the postfix expression.

Requirements

read the infix expressions from an input file (see example [url removed, login to view] below);

print the infix expressions to console;

convert the infix expressions to postfix;

print the postfix expressions to console;

read the operand values from an input file named (see example [url removed, login to view] below);

print the operand values to console;

use the operand values to evaluate the postfix expressions;

and finally print the result of evaluation to console.

[url removed, login to view] :

one infix expression per line

can have 1 or more lines

expressions can have spaces

only single characters for operands: a, b, c, ...

can contain only the following operators: + - * /

parentheses to specify order of operation

a + b

a*(b+c)

[url removed, login to view] :

only one entry per operand

one <operand> <value> pair per line

values can be floating point

a 3.6

b 5.2

c 2.0

Design

Infix to Postfix conversion:

The stack will contain operators, while the queue will contain the final postfix expression.

Read the infix expression character by character, left to right

If the scanned character is an operand, enqueue it

If the scanned character is an open parenthesis, push it to the stack.

If the scanned character is a close parenthesis, pop all operators from the stack and enqueue them until the opening parenthesis is reached.

Discard the open and close parentheses.

If the scanned character is an operator and the stack is empty or there is an open parenthesis on the top of the stack, push the scanned character on the stack.

If the scanned character is an operator and the stack is not empty, compare the precedence of the scanned character to that on the top of the stack:

If the precedence on the top of the stack is higher than or equal to the scanned character, pop the stack and enqueue the popped value

Otherwise push the scanned character on the stack.

Repeat this as long as the stack is not empty and character on the top of the stack has a higher precedence over the scanned character.

Repeat 3-7 until all characters in input string have been scanned.

If stack is not empty, pop all remaining operators and enqueue them.

Once complete, the queue contains the postfix expression.

Postfix evaluation:

While the queue is not empty:

Enqueue each character of the postfix expression

While the queue is not empty:

Dequeue from the queue

If an operand is dequeued, find its value and push it on the stack.

If an operator is dequeued, pop the stack twice, perform the operation and push result.

Once complete, the stack should only the result of the expression.

A diagram laying out the classes and methods is attached.

Compétences : Java, Développement de logiciel

Concernant l'employeur :
( 19 commentaires ) Hammond, United States

Nº du projet : #8744777

## Décerné à:

vano101

Hello. I solved this task many times and I am able to solve it in few hours from scratch..............

%selectedBids___i_sum_sub_4% %project_currencyDetails_sign_sub_5% USD en 1 jour
(614 Commentaires)
6.7

## 5 freelance font une offre moyenne de \$45 pour ce travail

azeem18

Hi there, I am a software engineer. I can do your project with great accuracy .Feel free to ask me anything.

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(39 Commentaires)
4.9
ahmsak

A proposal has not yet been provided

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(11 Commentaires)
4.7
NaveenNishaan

A proposal has not yet been provided

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 3 jours
(17 Commentaires)
4.2
sangeeta1988

My interest towards data structures and logically implementation of this kind of problems. Working on java technology since 3 years of development.

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 5 jours
(4 Commentaires)
2.7