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. Quote Link to comment https://forums.phpfreaks.com/topic/73422-simple-java-programm/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.