使用javaScript实现一个堆链表

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();
    }
}

运行结果

原文地址:https://www.cnblogs.com/MySweetheart/p/13217443.html