Question: use C + + to solve: Implement a generic stack container. Implement a program that converts infix expression to postfix expression and implement a program
use C to solve: Implement a generic stack container. Implement a program that converts
infix expression to postfix expression and implement a program that evaluates postfix
expression using the stack container you developed.
Project Description:
A stack is a type of data containerdata structure that implements the LASTINFIRSTOUT
LIFO strategy for inserting and recovering data. This is a very useful strategy, related to many
types of natural programming tasks.
Remember that in the generic programming paradigm, every data structure is supposed to
provide encapsulation of the data collection, enabling the programmer to interact with the entire
data structure in a meaningful way as a container of data. By freeing the programmer from
having to know its implementation details and only exporting the interface of its efficient
operations, a generic Stack provides separation of data accessmanipulation from internal data
representation. Programs that access the generic Stack only through the interface can be re
used with any other Stack implementation, which results in modular programs with clear
functionality and that are more manageable
Goals:
Implement a generic Stack.
Write a program that parses Infix arithmetic expressions to Postfix arithmetic
expressions using a Stack.
Write a program that evaluates Postfix arithmetic expressions using a Stack. Task : Convert Infix Arithmetic Expressions into PostFix Arithmetic Expressions and
evaluate them whenever possible
For the sake of this exercise, an arithmetic expression is a sequence of spaceseparated
strings. Each string can represent an operand, an operator, or parentheses.
Examples of operands: a and balphanumeric
Operators: one of the characters or As usual, and are regarded as having
higher precedence than or
Parentheses: or
An Infix arithmetic expression is the most common form of arithmetic expression used.
Examples:
is an infix arithmetic expression that evaluates to
is an infix arithmetic expression that evaluates to
For the sake of comparison, postfix arithmetic expressions also known as reverse Polish
notation equivalent to the above examples are:
Two characteristics of the Postfix notation are any operator, such as or is applied to
the two prior operand values, and it does not require ever the use of parentheses.
More examples:
a b c dd e f G in Infix notation becomes a b c dd e f G in Postfix
notation.
To implement Infix to Postfix conversion with a stack, one parses the expression as sequence of
spaceseparated strings. When an operand ie an alphanumeric string is read in the input, it
is immediately output. Operators ie may have to be saved by placement in the
operatorstack. We also stack left parentheses. Start with an initially empty operatorstack.
Follow these rules for processing operatorsparentheses:
If input symbol is push it into stack.
If input operator is or repeatedly print the top of the stack to the output
and pop the stack until the stack is either i empty; ii a is at the top of the stack; or
iii a lowerprecedence operator is at the top of the stack. Then push the input operator
into the stack.
If input operator is and the last input processed was an operator, report an error.
Otherwise, repeatedly print the top of the stack to the output and pop the stack until a
is at the top of the stack. Then pop the stack discarding the parenthesis. If the stack is
emptied without a being found, report error.
If end of input is reached and the last input processed was an operator or report error.
Otherwise print the top of the stack to the output and pop the stack until the stack is
empty. If an is found in the stack during this process, report error.
Evaluating Postfix Arithmetic Expressions
After converting a given expression in Infix notation to Postfix notation, you will evaluate the
resulting arithmetic expression IF all the operands are numeric int float, etc. values.
Otherwise, if the resulting Postfix expression contains characters, your output should be equal
to the input.
Example inputs:
c Example outputs:
c
To achieve this, you will have an operandstack, initially empty. Assume that the expression
contains only numeric operands no variable names Operands are pushed into the stack as
they are ready from the input. When an operator is read from the input, remove the two values
on the top of the stack, apply the operator to them, and push the result onto the stack.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
