当前位置: 首页 > 图文教程 > 网络编程 > Javascript > javascript写的一个链表实现代码

Javascript
javascript 新浪背投广告实现代码
javascript 选择文件夹对话框(web)
JS 自动完成 AutoComplete(Ajax 查询)
javascript scrollLeft,scrollWidth,clientWidth,offsetWidth 完全详解
jQuery 插件开发 其实很简单
最简单的jQuery程序 入门者学习
javascript 读取xml,写入xml 实现代码
JQuery 实现的页面滚动时浮动窗口控件
javascript 动态加载 css 方法总结
javascript 表格左右收缩
jqurey 学习笔记 传智博客佟老师附详细注释
javascript dom 操作详解 js加强
JS 动态添加列表框项效果代码
Javascript 事件流和事件绑定
Google Map Api和GOOGLE Search Api整合实现代码
9个javascript语法高亮插件 推荐
Prototype String对象 学习
javascript ImgBox透明遮罩层背景图片展示
javascript FAQ函数(提问+回复)
jQuery TextBox自动完成条

Javascript 中的 javascript写的一个链表实现代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 127 ::
收藏到网摘: n/a

今天在百度上看到有人问怎么用Javascript 写一个学生管理系统。个人认为没有什么实现价值。无聊练练手吧,很久没写JS了。 本来要用Array来保存数据的,没试过用JS来数据结构,就用JS来试试吧。
JS效率真的很低一个链表装1000个对象浏览器就提示运行缓慢了。
之前觉得AJAX3D挺用前景的,现在看来还没有流行就要夭折了。用delphi开发的游戏人们都觉得太慢了,何况用JS。
下面是我实现的一个链表:
复制代码 代码如下:

/*@author eric
*@mail [email protected]
*blog.csdn.net/shmilyhe
*/
<script>
function Student(no,name){
this.id=no;
this.name=name;
this.scores={chinese:0,math:0,english:0};
}
function List(){
this.head=null;
this.end=null;
this.curr=null;
}
List.prototype.add=function(o){
var tem={ob:o,next:null};
if(this.head){
this.end.next=tem;
this.end=tem;
}else{
this.head=tem;
this.end=tem;
this.curr=tem;
}
}
List.prototype.del=function(inde){
var n=this.head;
for(var i=0;i<inde;i++){
n=n.next;
}
n.next=n.next.next?n.next.next:null;
}
List.prototype.next=function(){
var te=null;
if(this.curr){
te=this.curr.ob; this.curr=this.curr.next;}
return te;
}
List.prototype.hasnext=function(){
if(this.curr.ob!=null)return true;
return false;
}
var list=new List();
for(var i=0;i<1000;i++){
list.add(new Student(i,'name'+i));
}
var i=0;
while(list.hasnext()){
document.writeln(list.next().name);
if(i==10){document.writeln('<br/>'); i=0;}
i++;
}
</script>