Postfix notation is a way of writing expressions without using parentheses. For example, the expression (1 + 2) * 3 would be written as 1 2 + 3 *. A postfix expression is evaluated using a stack. Scan a postfix expression from left to right. A variable or constant is pushed into the stack. When an operator is encountered, apply the operator with the top two operands in the stack and replace the two operands with the result. The following diagram shows how to evaluate 1 2 + 3 *: 1.1 12+3* scanned 12+3* A scanned 3 12+3* scanned 3 12+3* scanned 9 12+3* scanned

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 9SA
icon
Related questions
Question
input:
23+7*
26+9/
14 2 + 160/
99 2 + 50/24 -
100 4/3 * 20 +
143 *19 + 12/3+7*
23 7 + 10 * 14 + 19 - 22 * 16/
output:
expression 23 +7* evaluates to 35
expression 2 6 + 9 / evaluates to 0
expression 14 2 + 160/ evaluates to 0
expression 99 2 + 50 / 24 - evaluates to -22
expression 100 4/3 * 20+ evaluates to 95
expression 14 3 * 19 + 12/3 + 7* evaluates to 56
expression 23 7 + 10 * 14 + 19 - 22 * 16/ evaluates to 405
Transcribed Image Text:input: 23+7* 26+9/ 14 2 + 160/ 99 2 + 50/24 - 100 4/3 * 20 + 143 *19 + 12/3+7* 23 7 + 10 * 14 + 19 - 22 * 16/ output: expression 23 +7* evaluates to 35 expression 2 6 + 9 / evaluates to 0 expression 14 2 + 160/ evaluates to 0 expression 99 2 + 50 / 24 - evaluates to -22 expression 100 4/3 * 20+ evaluates to 95 expression 14 3 * 19 + 12/3 + 7* evaluates to 56 expression 23 7 + 10 * 14 + 19 - 22 * 16/ evaluates to 405
Postfix notation is a way of writing expressions without using
parentheses. For example, the expression (1 + 2) * 3 would be written
as 1 2 + 3 *. A postfix expression is evaluated using a stack. Scan a
postfix expression from left to right. A variable or constant is pushed
into the stack. When an operator is encountered, apply the operator
with the top two operands in the stack and replace the two operands
with the result. The following diagram shows how to evaluate 1 2 + 3 *:
12+3*
scanned
2
12+3*
scanned
3
12+ 3
scanned
3
3
12+3*
scanned
|₂|
9
12+ 3
scanned
Create a stack module that uses myStack.h and myStack.cpp by
implementing the api described in myStack.h. Write a test driver
named stackTest that uses your stack code to processes the Reverse
Polish notation examples given below. Submit the myStack.h,
myStack.cpp, and mystackTest.cpp to class myStack.
Here is a list of a few RPN expressions you can try and their
corresponding arithmetic values. These RPN expression are to be
read from a file named rpnArithmetic.txt
Transcribed Image Text:Postfix notation is a way of writing expressions without using parentheses. For example, the expression (1 + 2) * 3 would be written as 1 2 + 3 *. A postfix expression is evaluated using a stack. Scan a postfix expression from left to right. A variable or constant is pushed into the stack. When an operator is encountered, apply the operator with the top two operands in the stack and replace the two operands with the result. The following diagram shows how to evaluate 1 2 + 3 *: 12+3* scanned 2 12+3* scanned 3 12+ 3 scanned 3 3 12+3* scanned |₂| 9 12+ 3 scanned Create a stack module that uses myStack.h and myStack.cpp by implementing the api described in myStack.h. Write a test driver named stackTest that uses your stack code to processes the Reverse Polish notation examples given below. Submit the myStack.h, myStack.cpp, and mystackTest.cpp to class myStack. Here is a list of a few RPN expressions you can try and their corresponding arithmetic values. These RPN expression are to be read from a file named rpnArithmetic.txt
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
Binary numbers
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,