Code: Select all
function ArrayList() {
this.a_list = new Array(); function add(value) {
var currentIdx = this.size();
this.a_list[currentIdx] = value;
}
function get(idx) {
return this.a_list[idx];
}function remove(idx) {
for (x = idx; x < this.a_list.length; x++) {
this.a_list[x] = this.a_list[x+1];
}
this.a_list[this.a_list.length-1] = null;
}function size() {
var t_size = this.a_list.length;
if (t_size > 0 && this.a_list[this.a_list.length-1] == null) {
t_size--;
}
return t_size;
}function move(idxFrom,idxTo) {
var t_value = this.a_list[idxFrom];
//direction: move down
if (idxFrom < idxTo) {
for (x = idxFrom; x < idxTo; x++) {
this.a_list[x] = this.a_list[x+1];
}
this.a_list[idxTo] = t_value;
} else if ( idxTo < idxFrom) { //direction: move up
for (x = idxFrom; x > idxTo; x--) {
this.a_list[x] = this.a_list[x-1];
}
this.a_list[idxTo] = t_value;
}
}
function exchange(idxChange,idxWith) {
var t_value = this.a_list[idxWith];
this.a_list[idxWith] = this.a_list[idxChange];
this.a_list[idxChange] = t_value;
}
this.move = move;
this.remove = remove;
this.get = get;
this.add = add;
this.size = size;
this.exchange = exchange;
}
Just to make arrays more neat and simple. I created this Arraylist class myself.. Using with not much problem(there are still problems tho)
Any problems faced when using it, please post it here so that i can improve on it thanks