色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

javascript寫的一個鏈表實現代碼

本來要用Array來保存數據的,沒試過用JS來數據結構,就用JS來試試吧。
JS效率真的很低一個鏈表裝1000個對象瀏覽器就提示運行緩慢了。
之前覺得AJAX3D挺用前景的,現在看來還沒有流行就要夭折了。用delphi開發的游戲人們都覺得太慢了,何況用JS。
下面是我實現的一個鏈表:
復制代碼 代碼如下:
/*@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>

JavaScript技術javascript寫的一個鏈表實現代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 华宁县| 古浪县| 如东县| 梓潼县| 郯城县| 额尔古纳市| 闵行区| 雷山县| 治多县| 广宗县| 聊城市| 开鲁县| 油尖旺区| 玉龙| 神农架林区| 广水市| 怀仁县| 浦江县| 岳阳市| 和龙市| 许昌县| 邵阳县| 孟村| 深州市| 潍坊市| 博兴县| 临高县| 醴陵市| 桐城市| 搜索| 阳泉市| 正宁县| 武鸣县| 阳江市| 台安县| 横山县| 长春市| 太康县| 隆子县| 柳河县| 沛县|