Question: Create a stack class named MyStack that stores generics with the methods shown below. Write a test program that thoroughly tests your stack implementation. void

Create a stack class named MyStack that stores generics with the methods shown below. Write a test program that thoroughly tests your stack implementation.

void push(E item)

push item onto top of stack

E peek()

return item on top of stack

E pop()

return item on top of stack and remove it from the stack

boolean isEmpty()

returns whether or not stack is empty

Once the stack is working, create a class EvalPostfix that receives a postfix expression in String format, uses the MyStack class to evaluate the expression, and returns the resulting value. You may assume that all operands and operators (+ - * /) will be separated by a single space. Operands will be integers and may contain several digits. The class will require the following functions to be implemented:

EvalPostfix(String post)

constructor that sets the attribute containing the postfix string to be evaluated

int eval()

returns the result of the postfix expression

Write a test program named Prog5 that gets a postfix expression from the keyboard, uses EvalPostfix to evaluate the expression, and displays the result.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!