Question: Question 2 [6 + 8 Marks] (A) [6 Marks] Consider the generic class called ArrayStack as discussed in the lectures, having following data fields: private

 Question 2 [6 + 8 Marks] (A) [6 Marks] Consider the

Question 2 [6 + 8 Marks] (A) [6 Marks] Consider the generic class called ArrayStack as discussed in the lectures, having following data fields: private E( ) theData; // array to store stack elements private int topOfStack = -1; // Index to top of stack, initially empty stack. private static final int INITIAL_CAPACITY = 10; Write a method called replaceTop to be included in this class ArrayStack. If stack is not empty, then the method replaces the top element of the stack by parameter item and returns the old value at the top. If the stack is empty, return null. Do not call any other method of the class ArrayStack in your method. Example: top stack (Before method call): 5, 20, 10, 50, 15, 30 item: 7 top stack (After method call): 7, 20, 10, 50, 15, 30 Method will return 5. Method Heading: public E replaceTop (E item)

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!