Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that converts an infix expression into an equivalent postfix expression. The rules to convert an infix expression into an equivalent postfix expression

image text in transcribed

image text in transcribed

Write a program that converts an infix expression into an equivalent postfix expression. The rules to convert an infix expression into an equivalent postfix expression are as follows: Suppose infx represent the infix expression and pfx represents the postfix expression. The rules to convert inf x into pfx are as follows: a. Initialize pfx to an empty expression and initialize the stack b. Get the next symbol, sym, from infx. b.1 if sym is an operand, append sym to pfx. b.2 2 if sym is (, push sym into the stack. b.3 if sym is ), pop and append all the symbols from the stack until the most recent left parenthesis. Pop and discard the left parenthesis. b.4 if sym is an operator b.4.1. Pop and append all the operator from the stack to pfx that are above the most recent left parenthesis and have precedence greater than or equal to sym. b.4.2 Push sym onto the stack. c. After processing infx, some operators might be left in the stack. Pop and append to pfx everything from the stack. In this program, you will consider the following(binary) arithmetic operations: +,, , and /. You may assume that the expression you will process are error free. Design a class that stores the infix and postfix strings using linked list. The class must include the following operations: - Getinfix - stores the infix expression - showinfix - output the infix expression - showPostfix - output the postfix expression. Some other operations that you might need are the following: - convertToPostfix - converts the infix expression into a postfix expression. The resulting postfix expression is stored in pfx. - Precedence-Determines the precedence between two operators. If the first operator is of higher or equal precedence than the second operator, it returns the value true; otherwise, it returns the value true; otherwise, it returns the value false. Include the constructors and destructors for automatic initialization and dynamic memory deallocation. Test your program on the following five expressions: A+BC(A+B)C(A+B)(CD)A+((B+C)(EF)G)/(HI)A+B(C+D)E/FG+H For each expression, your answer must be in the following form: Infix Expression: A+BC; Postfix Expression: A B + C

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions

Question

an element of formality in the workplace between different levels;

Answered: 1 week ago