I have to define my own stack and store the elements of the stack into an ArrayList. My stack should have at least the methods push() that adds an element at the next available position in the ArrayList and and pop() that will get the last item of the ArrayList until the first one.
I am not asking anyone to do my work but I am having lots of trouble starting how to define a stack in which the elements are stored in an ArrayList. Can anyone please suggest me some good references on how I can actually start to create my Stack and how to create an ArrayList into my StackClass?
Thanks for reading my question and I sincerely appreciate any kind of help that will be provided.
What problems are you having? It's pretty straightforward. Add new items to the end of the list with List.add(). Take the last item off using remove(). Figure out the index to use (always the last one, since it's a stack) with size().