Question: import java.util.ArrayList; public class MyStack { private ArrayList list = new ArrayList(); public boolean isEmpty() { return list.isEmpty(); } public int getSize() { return list.size();

 import java.util.ArrayList; public class MyStack { private ArrayList list = new ArrayList(); public boolean isEmpty() { return list.isEmpty(); } public int getSize() { return list.size(); } public Object peek() { return list.get(getSize() - 1); } public Object pop() { Object o = list.get(getSize() - 1); list.remove(getSize() - 1); return o; } public void push(Object o) { list.add(o); } @Override /** Override the toString in the Object class */ public String toString() { return "stack: " + list.toString(); } }
 import java.util.ArrayList; public class MyStack { private ArrayList list = new

ASSIGNMENT 3 Arrays and ArrayList Submission Deadline Friday 19/3/2021 11:30 PM Implement the class MyStack (Chapter 11, slides 47 & 48) using normal arrays. Start your array with size 5. When push is called, if the array is full, replace it with an array that has the double of the original size and copy all elements in the new array. When pop is called and the number of elements in the array is less that the half of the available cells, replace the array with another one that has half the size and copy all elements in the new array

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!