KillerWolf Posted October 16, 2007 Share Posted October 16, 2007 ok this is what i have so far. import java.util.ArrayList; import java.util.EmptyStackException; public class Stacked { protected int top = -1; ArrayList stacked = new ArrayList(); public int size() { return (top + 1); } public ArrayList top() throws EmptyStackException { if (isEmpty()) throw new EmptyStackException(); return stacked[top]; } public void push(Object obj) { stacked.add(obj); } public Object pop() { if (stacked.isEmpty()) throw new EmptyStackException(); return stacked.remove(stacked.size()-1); } public boolean isEmpty() { return stacked.isEmpty(); } } i get this error " array required, but java.stack.util.ArrayList found" what is going on problem with this "return stacked[top];". what iam trying to do is make a stack using an arraylist. anyhelp or pointers on the overall code so far will be much apreciated iam new at java. Link to comment https://forums.phpfreaks.com/topic/73422-simple-java-programm/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.