Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 so that we can create stack objects that can hold data of different types, such as integer stack, string stack, char stack, double stack, etc.

it has to be in . which is a generic class. Example here public class MyStack {

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Which type of data is not accessed in a derived class?

Answered: 1 week ago

Question

India experiences which type of climate?

Answered: 1 week ago

Question

What is an aquifer?

Answered: 1 week ago