列表
List function List(){ this.dataStore = 0; this.insert = insert; this.find = find; this.append = append; this.remove = remove;
//插入 function insert(element, after) { var insertPos = this.find(after); if (insertPos > -1) { this.dataStore.splice(insertPos + 1, 0, element); ++this.listSize; return true; } return false; } //查找 function find(element) { for (var i = 0; i < this.dataStore.length; ++i) { if (this.dataStore[i] == element) { return i; } } return -1; } //数据末尾插入 function append(element) { this.dataStore[this.listSize++] = element; }
//删除 function remove(element) { var foundAt = this.find(element); if (foundAt > -1) { this.dataStore.splice(foundAt, 1); --this.listSize; return true; } return false; }
}
from:https://blog.csdn.net/haoshidai/article/details/52263191
圣凡无二路,方便有多门。