javascript写的一个链表实现代码
作者:bea
本来要用Array来保存数据的,没试过用JS来数据结构,就用JS来试试吧。 JS效率真的很低一个链表装1000个对象浏览器就提示运行缓慢了。 之前觉得AJAX3D挺用前景的,现在看来还没有流行就要夭折了。用delphi开发的游戏人们都觉得太慢了,何况用JS。 下面是我实现的一个链表: 代码如下: /*@author eric *@mail shmilyhe@163.com *blog.csdn.net/shmilyhe */ <script> fu
本来要用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>
有用 | 无用
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 关于# 和 void的区别分析
- 用Greasemonkey 脚本收藏网站会员信息到本地
- javascript 实现划词标记划词搜索功能
- 解决jquery .ajax 在IE下卡死问题的解决方法
- 解决表单中第一个非隐藏的元素获得焦点的一个方案
- innerhtml用法 innertext用法 以及innerHTML与innertext的区别
- 几个javascript操作word的参考代码
- javascript 操作Word和Excel的实现代码
- 禁止在图片上使用右键
- 在图片上单击获取图片原始大小
- 状态栏 时间显示效果 数字钟
- JavaScript 对话框和状态栏使用说明
- 5款Javascript颜色选择器
- 11款基于Javascript的文件管理器
- JavaScript 三种不同位置代码的写法
- JavaScript 事件的一些重要说明
- CSS 动态链接提示
- javascript 走马灯效果的链接提示
- Js 打字效果 逐一出现的文字