Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
9th Edition
ISBN: 9780134379319
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
String reversal is considered one of the applications of Stack data structure. You are required to; Write a java program to reverse a given string using stack ADT. Your program must implement a function named reverseMyId() for string reversal. Call reverseMyId() function in the main() function with your ACTUAL student Id as string and print it in the reverse order. For example, if your ACTUAL student id is s101145366, the program will output it as Show the snapshot of the output screen. Create two tables (as shown below) to display how the string is added to and removed from the stack. [Hint: Number of columns is equal to the number of characters in your string.]     For Insertion           …           …           …           …           …     For Deletion         …         …         …         …         …         …
Data Structure & Algorithm: Write a program to perform the following operations on a stack. a) Create functions for push and pop operations of the stack.b) Write a function to convert an infix expression to a postfix expression. Pass a one-dimensional character array P to the function as input (infix exp) and return character array Q (postfix exp). Test your program for the following input P : ( A – (B / C ) * D + E ) * F % G c) Write a function for the evaluation of a given postfix expression. For testing pass the postfix expression Q of part b and supply the following set of values. A = 90, B = 50, C = 2, D = 3, E = 1, F = 2, G = 5
Code with comments and output screenshot is must for an Upvote   Create a Java function that uses a stack and no arithmetic to compare the number of 0's and 1's in a string. If # of 0's is greater, return -1. If # of 1's is greater, return 1. If equal, return 0.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning