www.u8686.com-信息发布平台
function Hashtable()
{
this._hash = new Object();
this.add = function(key,value){
if(typeof(key)!="undefined"){
if(this.contains(key)==false){
this._hash[key]=typeof(value)=="undefined"?
null:value;
return true;
} else {
return false;
}
} else {
return false;
}
}
this.remove = function(key){delete this._hash[key];}
this.count = function(){var i=0;for(var k in this._hash){i++;}
return i;}
this.items = function(key){return this._hash[key];}
this.contains = function(key){ return typeof(this._hash[key])!
="undefined";}
this.clear = function(){for(var k in this._hash){delete
this._hash[k];}}
this.keys =function(){
var keys = new Array();
for (var i in this._hash) {
if (this._hash[i] != null)
keys.push(i);
}
return keys;
}
}
//var a = new Hashtable();
//a.add("aa");
//a.add("bb",2342);
//a.add("bb",2342);
//alert("sf");
//var k = new Array();
//alert("sf");
//k = a.keys();
//alert("sf");
//for(var i=0;i<k.length;i++){
// alert(k[i]);
//}
本文提供了一个使用JavaScript实现的HashTable数据结构的完整代码示例。该实现包括添加、删除、查找等基本操作,并支持获取元素数量及所有键的功能。
&spm=1001.2101.3001.5002&articleId=5002574&d=1&t=3&u=8533ed79c2ad42a58b04e9511a43992b)
2807

被折叠的 条评论
为什么被折叠?



