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();
javascript数据结构之链表字典
最新推荐文章于 2024-01-12 07:45:00 发布