欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript寫的一個鏈表實現(xiàn)代碼

 更新時間:2009年10月25日 17:35:43   作者:  
今天在百度上看到有人問怎么用Javascript 寫一個學(xué)生管理系統(tǒng)。個人認(rèn)為沒有什么實現(xiàn)價值。無聊練練手吧,很久沒寫JS了。
本來要用Array來保存數(shù)據(jù)的,沒試過用JS來數(shù)據(jù)結(jié)構(gòu),就用JS來試試吧。
JS效率真的很低一個鏈表裝1000個對象瀏覽器就提示運行緩慢了。
之前覺得AJAX3D挺用前景的,現(xiàn)在看來還沒有流行就要夭折了。用delphi開發(fā)的游戲人們都覺得太慢了,何況用JS。
下面是我實現(xiàn)的一個鏈表:
復(fù)制代碼 代碼如下:

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

相關(guān)文章

最新評論