JavaScript write a linked list to implement code _javascript skills

Source: Internet
Author: User
Originally want to use array to save data, did not try to use JS to data structure, use JS to try it.
JS efficiency is really very low a list of 1000 objects browser prompts you to run slowly.
Before think Ajax3d quite use the foreground, now it seems to have not been popular will die prematurely. With Delphi development of the game people feel too slow, not to mention the use of JS.
Here is a list of the links I've implemented:
Copy Code code as follows:

/* @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>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.