Question: INFIX/PREFIX BY USING STACKS C++ // It converts an infix expression exp to its equivalent prefix form. string infix2prefix( const string exp ); //It evaluates
INFIX/PREFIX BY USING STACKS C++
// It converts an infix expression exp to its equivalent prefix form.
string infix2prefix( const string exp );
//It evaluates a prefix expression.
double evaluatePrefix( const string exp );
You MUST use stacks in your implementation. Thus, you will define a class for the ADT stack and use it in your functions. Note that you are allowed to use the C++ codes that are given in your textbook. In your algorithms, you may have the following assumptions: 1. The input strings are syntactically correct expressions. For example, you may assume that the string is a valid infix expression when the infix2prefix function is called or you may assume that the string is a valid prefix expression when the evaluatePrefix function is called. 2. An input string can include only digits and binary operators. You may assume that only the binary operators *, /, +, and - are allowed (no unary and exponentiation operators are allowed). Moreover, you may assume that operands are single digits (digits from 1 to 9). In case of infix expressions, the string can also include parentheses in addition to digits and binary operators. For simplicity, you may assume that there are no spaces between the digits and the operators.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
