Question
Develop a new class , called MyStackW , to implement, among others, key stack operations [ push(e), pop(), peek(), size(), isEmpty(),toString() ]we discussed in the
Develop a new class, calledMyStackW, to implement, among others, key stack operations [push(e), pop(), peek(), size(), isEmpty(),toString()]we discussed in the class. Class Stack needs to be defined as generic stack with type
it has to be in
Furthermore,define class Node as part of class Stack,
StackWClass must have these methods
- methodname(argument): return type
-isEmpty(): Boolean Returns true if this stack is empty
-size(): int Returns the number of elements in this stack
-peek(): E Returns the top element in this stack
-pop(): E Returns and removes the top element in this stack
-push(E element): E Adds a new element to the top of this stack
-search(E element): intReturns the position of the specified element in this stack
-toString(): StringReturns the String with all elements in current stack
Next, develop a simple test program calledTestStackW, to test each stack operation listed above and defined in your classStack. Useinteger type stack for the test program. Show the stack content before and after calling a stack operation. Use proper labels. Please DO NOT hard-code test data. Make sure to allow the user to enter the stack content using interactive menu (embedded inside the sentinel loop) Make it in ArrayStack version NOT in LinkedList.
-----MAIN MENU-----
0 - Exit Program
1 - Push
2 - Pop
3 - Peek (Top)
4 - Size
5 - Is Empty?
6 - Print Stack After This step Implement a class, call itExprW, which will be used for transforming the expressions (infix to postfix) and evaluate postfix.
implement a method
public static String infixToPostfix(String infix){
// Implement appropriate codes here
// Return postfix as a returned String of this method
}
Use yourMyStackW to implement the procedure of transformation from infix to postfix. Use the algorithm of infix to postfix translation. translate infix expression to postfix expression.
Assumption:
Input infix string doesn't have whitespaces.
All input number is one-digit number (positive digit 0 to 9)
Input infix can include parenthesis ( )
Operator + - * / ^ can be used
The output postfix string doesn't have whitespaces
you cannot change method names
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