标签:style blog io os ar java for strong 数据
列表:
function List() {
this.listSize = 0;
this.pos = 0;
this.dataStore = [];
this.find = find;
.........................
}
function append(element) { this.dataStore[this.listSize++] = element; }
function find(element) {
for(var i=0; i < this.dataStore.length; ++i) {
if(this.dataStore[i] === element) {
return 1;
}
}
return -1;
}
function remove() {
var foundAt = this.find(element);
if(foundAt > -1) {
this.dataStore.splice(foundAt,1);
--this.listSize;
return true;
}
return false;
}
function length() {
return this.listSize;
}
function toString() {
return this.dataStore;
}
function insert(elem,after) {
var insertPos = this.find(elem);
if(insertPos > -1) {
this.dataStore.splice(insertPos+1,0,elem); //
++this.listSize;
return true;
}
return false;
}
function clear() {
delete this.dataStore;
this.dataStore = [];
this.listSize = this.pos = 0;
}
function contains(elem) {
for(var i = 0; i < this.dataStore.length; ++i) {
if(this.dataStore[i] === elem) {
return true;
}
}
return false;
}
function front() {
this.pos = 0; //pos范围[0-listSize-1]
}
function end() {
this.pos = this.listSize - 1;
}
function prev() {
if(this.pos > 0) {
--this.pos;
}
}
function next() {
if(this.pos < this.listSize-1) {
++this.pos;
}
}
function currPos() {
return this.pos;
}
function moveTo(position) {
this.pos = position;
}
function getElement() {
return this.dataStore[this.pos];
}
标签:style blog io os ar java for strong 数据
原文地址:http://www.cnblogs.com/jinkspeng/p/4021503.html