作家
登录

javascript写的一个链表实现代码

作者: 来源:www.28hudong.com 2013-03-30 02:13:37 阅读 我要评论

本来要用Array来保存数据的,没试过用JS来数据结构,就用JS来试试吧。 JS效率真的很低一个链表装1000个对象浏览器就提示运行缓慢了。 之前觉得AJAX3D挺用前景的,现在看来还没有流行就要夭折了。用delphi开发的游戏人们都觉得太慢了,何况用JS。 下面是我实现的一个链表: 复制代码 代码如下: /*@author eric *@mail shmilyhe@163.com *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>

  推荐阅读

  JavaScript 图片放大效果及代码说明

Magnifier #magnifier{ width:342px; height:420px; position:absolute; top:100px; left:250px; font-size:0; border:1px solid #000; } #img{ width:342>>>详细阅读


本文标题:javascript写的一个链表实现代码

地址:http://www.17bianji.com/kaifa2/JS/27869.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)