Write C++ code to convert a given infix expression to postfix expression.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write C++ code to convert a given infix expression to postfix expression.

The steps and table below shows how infix to postfix conversion works in

practice .

1. Search the Infix string from left to right.

2. Initialize a vacant stack.

3. If the scanned character is an operand add it to the Postfix string.

4. When the scanned character is an operator and if the stack is empty push the

character to stack.

 

5. If a scanned character is an Operator and the stack is not empty, compare the

precedence of the character with element on top of the stack.

6. When top Stack has higher precedence over the scanned character pop the stack

else push the scanned character to stack. Repeat this procedure till the stack is not

empty and top Stack has precedence over the character.

7. Reiterate 4 and 5 steps till all characters are scanned.

8. After all characters are scanned, we have to add any character that the stack may

have to the Postfix string.

9. When stack is not empty add top Stack to Postfix string and Pop the stack.

Infix to Postfix Conversion
Infix Expression: (A/(B-C)*D+E)
Symbol Scanned
Stack
Output
A
A
A
A
B
АВ
(/-
AB
ABC
ABC-
(*
ABC-/
ABC-/D
ABC-/D*
ABC-/D*E
D
(*
(+
E
(+
Empty
ABC-/D*E+
Postfix Expression: ABC-/D*E+
Transcribed Image Text:Infix to Postfix Conversion Infix Expression: (A/(B-C)*D+E) Symbol Scanned Stack Output A A A A B АВ (/- AB ABC ABC- (* ABC-/ ABC-/D ABC-/D* ABC-/D*E D (* (+ E (+ Empty ABC-/D*E+ Postfix Expression: ABC-/D*E+
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education