Jump to content

simple java programm


Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.