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

运行结果

posted @ 2020-07-01 09:20  放学别跑啊  阅读(137)  评论(0编辑  收藏  举报