Question: Rewrite the MyStack class in Listing 11.10 to perform a deep copy of the list field. Listing 1 import java.util.ArrayList; 3 public class MyStack {

Rewrite the MyStack class in Listing 11.10 to perform a deep copy of the list field.

Listing

1 import java.util.ArrayList; 3 public class MyStack { private ArrayList list =

new ArrayList (); 4 5 public boolean isEmpty() { return list.isEmpty(); 10

1 import java.util.ArrayList; 3 public class MyStack { private ArrayList list = new ArrayList (); 4 5 public boolean isEmpty() { return list.isEmpty(); 10 11 12 13 14 public int getSize() { return list.size(); public Object peek() { return list.get(getSize() - 1); 15 16 17 public Object pop() { 18 19 Object o = list.get(getSize() - 1); list.remove (getSize() - 1); 20 21 | 22 23 24 25 26 27 28 29 return o; public void push(0bject o) { list.add(0); @Override public String toString() { return "stack: "+ list.toString(); 30 31 32 }

Step by Step Solution

3.53 Rating (173 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Program Plan 1 Create a class MyStack2 Declare and Initialize the List variable private ArrayList li... View full answer

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 Java Programming Questions!