Implementation Code of a linked list written in javascript

Source: Internet
Author: User

Originally, we wanted to use Array to store data. We didn't try to use JS to structure the data. Let's try it with JS.
JS efficiency is really low. When a linked list is installed with 1000 object browsers, it prompts that the operation is slow.
Previously, I thought that AJAX3D was quite promising. Now it seems that there is no popularity, and it is about to die. Games developed using delphi are too slow, not to mention JS.
The following is a linked list implemented by me:
Copy codeThe Code is 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.