function List(){
this.listSize = 0;
this.pos = 0;
this.dataStore = [];
this.clear = clear;
this.find = find;
this.toString = toString;
this.insert = insert;
this.append = append;
this.remove = remove;
this.front = front;
this.end = end;
this.prev = prev;
this.next = next;
this.length = length;
this.currPos = currPos;
this.moveTo = moveTo;
this.getElement = getElement;
this.coutains = coutains;
}
append给列表添加元素
function append(element){
this.dataStore[this.listSize++] = element;
}
find在列表中查找某一元素
function find(element){
for(var i = 0; i < this.dataStore.length;++i){
if(this.dataStore[i]==element){
return i;
}
}
return -1;
}
remove从列表中删除元素
function remove(element){
var founAt = this.find(element);
if(founAt>-1){
this.dataStore.splice(founAt,1);
--this.listSize;
return true;
}
return false;
}
length列表中有多少个元素
function length(){
return this.listSize;
}
toString显示列表中的元素
function toString(){
return this.dataStore;
}
insert向列表中插入一个元素
function insert(element,after){
//after 插入那个元素后
var insertPos = this.find(after);
if(insert>-1){
this.dataStore.splice(insertPos+1,0,element);
++this.listSize;
return true;
}
return false;
}
}
clear清空列表中所有的元素
function clear(){
delete this.dataStore;
this.dataStore = [];
this.listSize = this.pos = 0;
}