Java Data Structure series-stack (2): Stack chain storage structure and its operations, java Data Structure
Package Stack; import LinkList. singlyLinkList; public class LinkListStack {private SinglyLinkList <Integer> singlyLinkList;/*** default constructor, used to initialize the stack */public LinkListStack () {singlyLinkList = new SinglyLinkList <Integer> () ;}/ ** stack pressure operation */public void push (int value) {singlyLinkList. addFromHead (value);} public Integer peek () {if (isEmpty () {// if the stack is empty throw new RuntimeException ("the element in the stack is empty ");} return singlyLinkList. getFirst ();}/*** out-of-stack operation * @ return */public Integer pop () {if (isEmpty ()) {// If the stack is empty throw new RuntimeException ("the element in the stack is empty");} return singlyLinkList. removeFromHead ();}/*** determines whether the stack is empty * @ return */public boolean isEmpty () {return singlyLinkList. isEmpty ();}}