/*
* List 大小可变数组
*/
function List() {
this.list = new Array();
}; /**
* 将指定的元素添加到此列表的尾部。
* @param object 指定的元素
*/
List.prototype.add = function(object) {
//this.list[this.list.length] = object;
this.list.push(object);
}; /**
* 将List添加到此列表的尾部。
* @param listObject 一个列表
*/
List.prototype.addAll = function(listObject) {
this.list = this.list.concat(listObject.list);
}; /**
* 返回此列表中指定位置上的元素。
* @param index 指定位置
* @return 此位置的元素
*/
List.prototype.get = function(index) {
return this.list[index];
}; /**
* 获取元素在数组中的坐标,不存在则返回-1
* @return true or false
*/
List.prototype.getObjectIndex = function(object) {
var i = 0;
for(; i < this.list.length; i++) {
if( this.list[i] === object) {
return i;
}
}
return -1;
}; /**
* 移除此列表中指定位置上的元素。
* @param index 指定位置
* @return 此位置的元素
*/
List.prototype.removeIndex = function(index) {
var object = this.list[index];
this.list.splice(index, 1);
return object;
}; /**
* 移除此列表中指定元素。
* @param object 指定元素
* @return 此位置的元素
*/
List.prototype.remove = function(object) {
var i = this.getObjectIndex(object); if(i==-1) {
return null;
} else {
return this.removeIndex(i);
}
}; /**
* 移除此列表中的所有元素。
*/
List.prototype.clear = function() {
this.list.splice(0, this.list.length);
}; /**
* 返回此列表中的元素数。
* @return 元素数量
*/
List.prototype.size = function() {
return this.list.length;
}; /**
* 返回列表中指定的 start(包括)和 end(不包括)之间列表。
* @param start 开始位置
* @param end 结束位置
* @return 新的列表
*/
List.prototype.subList = function(start, end) {
var list = new List();
list.list = this.list.slice(start, end);
return list;
}; /**
* 如果列表不包含元素,则返回 true。
* @return true or false
*/
List.prototype.isEmpty = function() {
return this.list.length == 0;
};

最新文章

  1. ngCordova插件安装使用
  2. spring aop搭建redis缓存
  3. C++ 创建和遍历二叉树
  4. Hibernate入门4.核心技能
  5. 队列——解密QQ号
  6. ubuntu桌面进不去,我跪了
  7. windows batch语法
  8. Linux启动Apache支持.htaccess伪静态文件方法
  9. Android内核剖析读书笔记
  10. UIImagePickerController Class 概述
  11. WPF textbox 圆角制作
  12. GTW likes math(BC 1001)
  13. ajax、form提交乱码
  14. 推荐几个JSON工具
  15. 2016-02-03 JS正则表达式
  16. 【JDK1.8】Java 8源码阅读汇总
  17. Hive 学习笔记(启动方式,内置服务)
  18. [Swift]LeetCode796. 旋转字符串 | Rotate String
  19. centos7下安装docker(20.docker swarm start)
  20. NOIP 飞扬的小鸟 题解

热门文章

  1. SEO从理论到实践
  2. Apple Developer Registration and DUNS Number Not Accepted
  3. CALayer(持续更新)
  4. Unity3d通用工具类之NGUI图集分解
  5. ArcEngine 连接sql server sde
  6. JConsole详解
  7. 启明星Exchange/outlook预定会议室终端显示解决方案
  8. Miscellaneos:版本控制、SVN、VSS
  9. libjson 编译和使用 - 2. 配置使用lib文件
  10. Balanced Binary Tree leetcode java