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>