js实现列表类
来源:互联网 发布:松下fpwin编程手册 编辑:程序博客网 时间:2024/06/06 02:34
<script text="text/javascript">function List(){ this.listSize=0; this.pos=0; this.dataStore=[]; this.clear=clear; this.find=find; this.toString=toString; this.insert=insert; this.append=append; this.remove=remove; this.front=front; this.end=end; this.prev=prev; this.next=next; this.length=length; this.currPos=currPos; this.moveTo=moveTo; this.getElement=getElement; this.length=length; this.contains=contains;}function append(element) {this.dataStore[this.listSize++] = element;}function find(element) { for (var i = 0; i < this.dataStore.length; ++i) { if (this.dataStore[i] == element) { return i; } } return -1;}function remove(element) { var foundAt = this.find(element); if (foundAt > -1) { this.dataStore.splice(foundAt,1); --this.listSize; return true; } return false;}function length() { return this.listSize;}function toString() { return this.dataStore;}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 clear(){ delete this.dataStore; this.dataStore = []; this.listSize = this.pos = 0;}function contains(element) { for (var i = 0; i < this.dataStore.length; ++i) { if (this.dataStore[i] == element) { return true; } } return false;}function front() {this.pos = 0;}function end() {this.pos = this.listSize-1;}function prev() { if (this.pos > 0) { --this.pos; }}function next() { if (this.pos < this.listSize-1) { ++this.pos; }}function currPos() {return this.pos;}function moveTo(position) {this.pos = position;}function getElement() {return this.dataStore[this.pos];}function doTest(){ var names = new List(); names.append("Clayton"); names.append("Raymond"); names.append("Cynthia"); names.append("Jennifer"); names.append("Bryan"); names.append("Danny"); names.front(); document.write(names.getElement()); names.next(); document.write(names.getElement()); names.next(); names.next(); names.prev(); document.write(names.getElement());}</script>
0 0
- js实现列表类
- js实现列表滚动
- js实现全国城市列表
- JS实现下拉列表联动
- 笔记-js实现彩虹列表
- js+div实现的下拉列表
- JS实现动态添加列表框项
- js 实现下拉列表的重复利用
- js实现左右列表内容交换传递
- JS get实现数据列表的修改
- js实现列表无间隙循环滚动
- JS 实现列表与多选框选择
- dtree.js菜单列表加密,实现Code
- JS实现生日选择下拉列表
- js实现两个列表框交换数据
- 二级联动下拉列表JS+html实现
- js实现跨浏览器好友列表
- 二级联动下拉列表JS+html实现
- 73 HTTP通信基本概念
- 快速学习HTML开发(从学习到项目上线用3周时间)
- Android-Service (基本知识,生命周期,实例-startService 启动的服务音乐播放器后台服务播放)
- js中数字类型数组排序
- 西普CTF部分题目(解密)
- js实现列表类
- js中数组迭代函数—(1)不生成新数组
- ERROR: ORACLE initialization or shutdown in progress 解决方案
- js中数组迭代函数—(2)会生成新数组
- 【转自mos文章】数据库 hang问题的诊断信息收集方法
- js实现栈
- 00初识python3
- 不要把 Python 写成 C 语言版的 Python
- USACO 1.1 Broken Necklace