Reputation: 1
import java.util.ArrayList;
public class MyStack<T> {
private ArrayList<T> stack;
// Copy constructor
public MyStack(MyStack<T> s) {
// i know its wrong
for(int i = 0; i < stack.size(); i++) {
this.stack.get(i) = s.stack.get(i);
}
}
}
Upvotes: 0
Views: 296
Reputation: 533730
How about
// Copy constructor
public MyStack(MyStack<T> s) {
this.stack = new ArrayList<T>(s.stack);
}
Upvotes: 3
Reputation: 2285
Have you tried to debug at all? An obvious suggestion would be to make sure that you're referencing the correct stack.
Upvotes: 0