class StackLInkedList{ constructor(){ this.items = new DoublyLinkedList();//https://www.cnblogs.com/MySweetheart/p/13212702.html } push(element){ this.items.push(element); } pop(){ if(this.isEmpty()){ return 'stack is null'; } return this.items.removeAt(this.size()-1); } peek(){ return this.items.getElementAt(this.size()-1).element; } isEmpty(){ return this.items.isEmpty(); } size(){ return this.items.size(); } clear(){ return this.items.clear(); } toString(){ return this.items.toString(); } }
运行结果