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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started