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

Javascript
JavaScript 自动完成脚本整理(33个)
7个Javascript地图脚本整理
JavaScript 事件记录使用说明
Javascript remove 自定义数组删除方法
fireworks菜单生成器mm_menu.js在 IE 7.0 显示问题的解决方法
Jquery Ajax.ashx 高效分页实现代码
extjs 学习笔记 四 带分页的grid
javascript void(0)的妙用
用Javascript 编写可以缓慢弹出收缩的层
再谈ie和firefox下的document.all属性
JavaScript 常用函数库详解
JS 截取字符串substr 和 substring方法的区别
Domino中运用jQuery读取视图内容的方法
Js+CSS 文字渐隐渐现显示
Javascript 小写字母依次变为大写
JavaScript 炫彩的文字
javascript 洒脱飘动的文字
JavaScript 平滑文字闪烁
仿打字特效的JS逐字出现的信息文字
JavaScript数组应用 可依次读取的公告栏文字

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 45 ::
收藏到网摘: 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>