Home  >  Article  >  Web Front-end  >  A linked list implementation code written in javascript_javascript skills

A linked list implementation code written in javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:43:211142browse

Originally I was going to use Array to save data, but I haven’t tried using JS to structure the data, so I’ll give it a try using JS.
JS efficiency is really low. If a linked list contains 1,000 objects, the browser will run slowly.
I used to think that AJAX3D had great potential, but now it seems that it will die before it becomes popular. People feel that games developed with Delphi are too slow, let alone using JS.
The following is a linked list I implemented:

Copy the code The code is as follows:

/ *@author eric
*@mail shmilyhe@163.com
*blog.csdn.net/shmilyhe
*/
<script> <br>function Student(no,name){ <br>this.id=no; <br>this.name=name; <br>this.scores={chinese:0,math:0,english:0}; <br>} <br>function List(){ <br>this.head=null; <br>this.end=null; <br>this.curr=null; <br>} <br>List.prototype.add=function(o){ <br>var tem ={ob:o,next:null}; <br>if(this.head){ <br>this.end.next=tem; <br>this.end=tem; <br>}else{ <br> this.head=tem; <br>this.end=tem; <br>this.curr=tem; <br>} <br>} <br>List.prototype.del=function(inde){ <br>var n=this.head; <br>for(var i=0;i<inde;i ){ <BR>n=n.next; <BR>} <BR>n.next=n.next.next?n .next.next:null; <BR>} <BR>List.prototype.next=function(){ <BR>var te=null; <BR>if(this.curr){ <BR>te=this.curr .ob; this.curr=this.curr.next;} <BR>return te; <BR>} <BR>List.prototype.hasnext=function(){ <BR>if(this.curr.ob!=null )return true; <BR>return false; <BR>} <BR>var list=new List(); <BR>for(var i=0;i<1000;i ){ <BR>list.add(new Student(i,'name' i)); <BR>} <BR>var i=0; <BR>while(list.hasnext()){ <BR>document.writeln(list.next().name) ; <BR>if(i==10){document.writeln('<br/>'); i=0;} <br>i ; <br>} <br></script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn