Question: In java please, provided code. public class GenericStack { private java.util.ArrayList list = new java.util.ArrayList(); public int getSize() { return list.size(); } public E peek()
In java please, provided code.
public class GenericStack


Revise the GenericStack class in Listing 19.1 to implement the Stack using an array rather than an ArrayList. You will need to create an array with a generic type and also an int variable to keep track of how many elements are in the stack. You may use the code below as a starting point. In the above code, the array is called elements and with the variable size to keep a count of how many elements in the stack. You should check the array size before adding content to the stack - the push() method. If the array is full, create a new array that double the size of the current array and copy elements from current array to the new array. Hence, you need to finish up the code above by implementing the following methods: peek ( ) pop () push ( ) isempty () 1 and getsize () method. This method should return whatever the value in size is. Write your test code to have a stack of Strings and a stack of integers
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
