列表的抽象数据类型定义
属性/方法 | 描述 |
---|---|
listSize(属性) | 列表的元素个数 |
pos(属性 | 列表的当前位置 |
length(属性) | 返回列表中元素的个数 |
clear(方法) | 清空列表中的所有元素 |
toString(方法) | 返回列表的字符串形式 |
getElement(方法) | 返回当前位置的元素 insert(方法) |
front(方法) | 将列表的当前位置设移动到第一个元素 |
end(方法) | 将列表的当前位置移动到最后一个元素 |
prev(方法) | 将当前位置后移一位 |
next(方法) | 将当前位置前移一位 |
currPos(方法) | 返回列表的当前位置 |
moveTo(方法) | 将当前位置移动到指定位置 |
1. 通过构造函数定义 list 类
function list() {
this.listSize = 0;
this.pos = 0;
this.length = length;
this.dataStore = []; // 用来保存元素
this.find = find;
this.clear = clear;
this.insert = insert;
this.append = append;
this.remove = remove;
this.contains = contains;
this.toString = toString;
this.getElement = getElement;
this.front = front;
this.end = end;
this.prev = prev;
this.next = next;
this.currPos = currPos;
this.moveTo = moveTo;
}