Question: Tempelate Code::::: Postfix notation, is a mathematical notation in which operators follow their operands; for instance, to add 3 and 4, one would write 3


Tempelate Code:::::



Postfix notation, is a mathematical notation in which operators follow their operands; for instance, to add 3 and 4, one would write 3 4rather than 3 +4 (infix notation). If there are multiple operations, operators are given immediately after their second operands; so, the expression written 3 - 4 +5 in conventional notation would be written 3 4-5 + in postfix notation: 4 is first subtracted from 3, then 5 is added to the result. An advantage of postfix notation is that it removes the need for parentheses that are required by infix notation. While 3-4 x 5 can also be written 3-(4 x 5), which is different from (3-4) 5, in postfix notation, the former could be written 3 4 5 x-, while the latter could be written 3 4-5 x or 5 3 4-x (from Wikipedia) Stacks can be used to evaluate expressions in postfix notations by following these steps: . If a number is typed, push it on the stack. If an operation is typed, pop off two numbers from the stack, perform the operation, and push the result back on the stack. You should complete the Stack class and other functions in the template file (found on Carmen) so that when the user enters an expression in postfix notation, the program calculates and shows the result. In this assignment the user enters one-digit numbers only, but the result can be any integer. Only basic operations (i.e. +.-./, *) are entered by the user and integer division is used in calculations. User input ends with a semicolon. Class Stack uses a linked list to implement a stack, and it has five public member functions: Default constructor: initializes the stack to an empty stack isEmpty: retums true if stack is empty and false otherwise push: pushes a new number to the top of stack pop: removes the top of stack, does not return it top: returns the value at the top of stack, does not remove it from staclk There are also two private member function in class Stack for manipulating the internal linked list: headInsert and headRemove (Why they don't have a parameter for head of the list?). These functions are defined as private members because they are not a part of characteristics of a stack. A stack does not have operations for inserting to head of a list or removing from a list. It is just a data structure with a Last In, First Out property. So, we define list-related functions as private members. If we decide at some point to change how we implement the stack internally, e.g. use a vector instead, other programs that use this class do not need to change, because they are only using public members
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
