function Vector(){
this.data = new Array();
this.add = Vector_add;
this.insert=Vector_insert
this.elementAt = Vector_elementAt;
this.removeAll = Vector_removeAll;
}
function Vector_removeAll(){
return this.data=[];
}
function Vector_add(item){
this.data[ this.data.length ] = item;
}
function Vector_insert(index,item){
if(index==this.data.length){
this.add( item );
return;
}
var data = this.data;
var tmpdata = new Array();
var newindex = 0;
for(var i=0;i<data.length;i++){
if(i==index){
tmpdata[i]=item;
newindex++;
}
tmpdata[newindex]=data[i];
newindex++;
}
this.data=tmpdata;
}
function Vector_elementAt(index){
return this.data[ index ];
}
JS中自定义List
最新推荐文章于 2024-11-04 11:18:54 发布