栈的特性:先进后出
public class Stack<E> {
private ArrayList<E> list = new ArrayList<E>();
public void empty()
{
list.empty();
}
public boolean isEmpty()
{
return list.isEmpty();
}
public void push(E element)
{
list.add(element);
}
public E pop()
{
E element = null;
if(isEmpty())
{
throw new RuntimeException("栈为空");
}
element = list.get(list.size()-1);
list.sub(list.size()-1);
return element;
}
public E top()
{
E element = null;
if(isEmpty())
{
throw new RuntimeException("栈为空");
}
element = list.get(list.size()-1);
return element;
}
}