国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

javascript寫的一個鏈表實現代碼

2024-05-06 14:13:14
字體:
來源:轉載
供稿:網友
本來要用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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 云林县| 宝应县| 柯坪县| 长顺县| 长春市| 达尔| 离岛区| 凤山市| 资溪县| 丘北县| 双鸭山市| 德令哈市| 海林市| 紫金县| 安康市| 沂水县| 龙山县| 沙河市| 鸡东县| 吕梁市| 成安县| 安平县| 花莲市| 上思县| 滨海县| 永昌县| 东港市| 安顺市| 攀枝花市| 乌什县| 建湖县| 平果县| 三原县| 大宁县| 张家港市| 浑源县| 左贡县| 雅江县| 金溪县| 镇巴县| 阿尔山市|