En cours

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

Your program must:

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

Voir plus : using stack in java example, using expressions, string compare algorithm, stacks and stacks, queue algorithm in c, push algorithm, pair of lines, pair line, java to c convert, find the operator, find operators, find character in string c, 3 line diagram, data structures using stacks queues, stacks queues project project, stacks queues data structures using, android pdf read slide right left, program data structure using stack postfix, program using structure postfix evaluation, implementation stacks programs using jcreator pro, stacks queues, stacks queues cpp, read arabic right left

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..............

25 $ USD en 1 jour
(341 Commentaires)
6.2

6 freelance ont fait une offre moyenne de 46 $ 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.

30 $ USD en 1 jour
(14 Commentaires)
4.0
ahmsak

A proposal has not yet been provided

100 $ USD en 1 jour
(8 Commentaires)
3.4
NaveenNishaan

A proposal has not yet been provided

35 $ USD en 3 jours
(12 Commentaires)
3.7
dghq123

Hello, i can do your task. Award it to me. I am Java expert.

50 $ USD en 1 jour
(2 Commentaires)
1.7
sangeeta1988

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

35 $ USD en 5 jours
(0 Commentaires)
0.0