jsシミュレーションC铀中Listの簡単な例
/*
* List
* version: 1.0
*/
function List() {
this.list = new Array();
};
/**
* 。
* @param object
*/
List.prototype.add = function(object) {
this.list[this.list.length] = 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];
};
/**
* 。
* @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 = 0;
for(; i < this.list.length; i++) {
if( this.list[i] === object) {
break;
}
}
if(i >= this.list.length) {
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;
};