原理:链表功能强大,可在头或尾进行插入和删除。
public class ListToStack { LinkedListlinkedList = new LinkedList<>(); public void add(int value){ linkedList.addLast(value); } public int remove(){ return linkedList.removeFirst(); } public int peek(){ return linkedList.getFirst(); } public boolean isEmpty(){ return linkedList.isEmpty(); } } 总结:懂链表结构,so easy~