javascript数据结构之链表字典

function Dictionary() {
    this.add=add;
    this.data=new Array();
    this.find=find;
    this.remove=remove;
    this.display=display;
}

function add(key,value) {
    this.data[key]=value;
}

function find(key) {
    return this.data[key];
}

function remove(key) {
    delete this.data[key];
}

function display() {
    for(let key in Object.keys(this.data)) {
        console.log(key + " -> " + this.data[key]);
    }
}

let dic=new Dictionary();
dic.add("key1","java");
dic.add("key2","js");
dic.add("key3","go");
dic.display();

版权声明:本文为w1374401940原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。