Question: Exercise 2: You would recall from CS1101 that a stack is a last in, first out data structure that has push, pop and peek as

 Exercise 2: You would recall from CS1101 that a stack is

Exercise 2: You would recall from CS1101 that a stack is a last in, first out data structure that has push, pop and peek as its basic operations. In this exercise, you will create a simple generic stack class that is implemented with an ArrayList to store the stack elements. The UML diagram is given below GenericStack - stack: ArrayListT> + GenericStack0 + getSize): int +peekO: T +pop0: T + push(T element): void +isEmpty): boolean The initial part of the code is given below: import java.util.ArrayList public class GenericStack private ArrayList stack; //continue As an example of its use, write a small test (demo or client program) to create two stacks, one to hold strings and another to hold integer objects, and test the methods: GenericStack0; stack1.push("London");, stack1.push("Paris"); stack1.push("Halifax"), GenericStackInteger stack2 = new GenericStack() stack2.push(1) stack2.push(2), stack2.push(3)

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!