创建功能图()//图集合
//在此定义数据结构
var struct=function (密钥,值) {
this.key=key;
this.value=value;
}
//这是额外的方法
var put=function (密钥,值) {
for(varI=0; i this.arr.length; I ) {
if(this.ARR[I].key===key ) {
this.arr[i].value=value;
返回;
}
}
this.arr [ this.arr.length ]=new struct (key,value );
}
//获取的方法
varget=function(key ) {
for(varI=0; i this.arr.length; I ) {
if(this.ARR[I].key===key ) {
return this.arr[i].value;
}
}
返回空值;
}
//这是根据自己的需要定义的方法
vargetindex=function(index ) {
if(this.ARR.Length-1=index ) {
return this.arr[index].key;
}
返回空值;
}
//删除方法
varremove=function(key ) {
var v;
for(varI=0; i this.arr.length; I ) {
v=this.arr.pop (;
if(v.key*1===key*1) {
继续;
}
this.ARR.unshift(v;
}
}
//获取存储数量
var size=function
return this.arr.length;
}
//判断是否为空
var isEmpty=function
return this.arr.length=0;
}
//清空
var toNull=function
this.arr=new Array (;
}
//发布服务
this.arr=new Array (;
this.get=get;
this.put=put;
this.toNull=toNull;
this.remove=remove;
this.getIndex=getIndex;
this.getValue=getValue;
this.size=size;
this.isEmpty=isEmpty;
}