Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Java The first part of the project involves converting infix expressions to postfix using the shunting-yard algorithm and the stack and queue implementations you
In Java
The first part of the project involves converting infix expressions to postfix using the shunting-yard algorithm and the stack and queue implementations you wrote in lab 6. You should not use the stack and queue classes from the Java library. Each infix expression may contain any combination of the following mathematical operators: addition [+], subtraction [-], multiplication [*], division [1], parentheses [O], less than [], equal to [=], logical AND [&], logical OR []), and logical NOT [!]. When using the mathematical and logical operators together, let false be represented by 0 and true be represented by 1. Extra credit is available for programs that can support the following additional operators: exponentiation [^], modulo [%], sine (sin), cosine (cos), and tangent [tan). The shunting-yard algorithm works by considering each token (operand or operator) from an infix expression and taking the appropriate action: 1. If the token is an operand, enqueue it. 2. If the token is a close-parenthesis [')'], pop all the stack elements and enqueue them one by one until an open-parenthesis ['('] is found. 3. If the token is an operator, pop every token on the stack and enqueue them one by one until you reach either an operator of lower precedence, or a right-associative operator of equal precedence (e.g. the logical NOT is a right-associative operator). Enqueue the last operator found, and push the original operator onto the stack. 4. At the end of the input, pop every token that remains on the stack and add them to the queue one by one. With your postfix expression stored in the queue, the next step is to evaluate it. The algorithm for evaluating a postfix expression proceeds as follows: 1. Get the token at the front of the queue. 2. If the token is an operand, push it onto the stack. 3. If the token is an operator, pop the appropriate number of operands from the stack (e.g. 2 operands for multiplication, 1 for logical NOT). Perform the operation on the popped operands, and push the resulting value onto the stack. Repeat steps 1-3 until the queue is empty. When it is, there should be a single value in the stack that value is the result of the expressionStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started