Starting Out With C++: Early Objects (10th Edition)
Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
Question
Book Icon
Chapter 18, Problem 14PC
Program Plan Intro

Stack Based Evaluation of Postfix Expression

Program Plan:

  • Declare a function skipWhiteSpace that Skips whitespace in an input stream while evaluating a postfix expression.
  • Declare a Function postFixEval that evaluates the postfix expression by considering if the next token in the input stream is an integer, read  the integer and push it onto the stack using the push() operation of the stack .
    • But if the input stream is an operator, pop the last two values from the stack using the pop operation and apply the operator, and push the result onto the stack and the lone value is the result.
  • Declare the main function.
    • Prompt the user to enter a postfix expression.
    • Evaluate the postfix expression by calling the postFixEval function and print the result.

Blurred answer
Students have asked these similar questions
C# language Write a program that creates a Queue or Stack (your choice) that represents a list of work orders. This program should use loop, allowing the user to push and pop items on the stack / queue. The program should also allow the user to print all the items in the stack / queue to the console.
A sequence of instructions may be used to see the function's return address. Any modifications to the stack must be made with the return of the method to its caller in mind.
* This function evaluates the provided postfix expression. When an operand is encountered, it is added to the stack. When an operator is encountered, two operands are popped, the operation is evaluated, and the result is pushed to the stack.* @param expr string postfix expression representation * @return value of the supplied expression
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning