如下所示:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script> function Node(v){ this.value=v; this.next=null; } function ArrayList(){ this.head=new Node(null); this.tail = this.head; this.append=function(v){ node = new Node(v); this.tail.next=node; this.tail=node; } this.insertAt=function(ii,v){ node = new Node(v); //找到位置的节点 tempNode=this.head; for(i=0;i<ii;i++){ if(tempNode.next!=null){ tempNode=tempNode.next; }else{ break; } } node.next=tempNode.next; tempNode.next = node; } this.removeAt=function(ii){ node1=this.head; //要删除节点的前一个节点 for(i=0;i<ii;i++){ if(node1.next!=null){ node1=node1.next; }else{ break; } } node2=node1.next; //要删除的节点 if(node2!=null){ node1.next = node2.next; if(node2.next==null){ this.tail=node1; } } } } function Iterator(arryList){ this.point=arryList.head; this.hasNext=function(){ if(this.point.next!=null){ this.point=this.point.next; return true; }else{ return false; } } this.next=function(){ return this.point.value; } } var arry = new ArrayList(); arry.append(1); arry.append(2); arry.append(3); arry.insertAt(1,8); arry.insertAt(0,9); arry.insertAt(100,100); arry.insertAt(1000,1000); arry.insertAt(1,200); arry.insertAt(200,2000); iterator = new Iterator(arry); while(iterator.hasNext()){ document.write(iterator.next()); document.write('<br/>'); } </script> </head> <body> </body> </html>
以上这篇js链表操作(实例讲解)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 黄心懋1991-轻忧郁【滚石】【WAV+CUE】
- 群星.2000-大地金曲世纪回顾2CD【大地】【WAV+CUE】
- 王菲.1996-浮躁(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 群星.2022-传家电视剧原声带【东阳欢娱】【FLAC分轨】
- 《摇滚教父 伍佰黄金精选 2CD》 [WAV+CUE][1GB]
- 《凤凰传奇 我从草原来》[WAV/分轨][400MB]
- 《叶倩文 真心真意过一生》[WAV+CUE][400MB]
- 潘越云.1985-世间女子(滚石25周年经典复刻版)【滚石】【WAV+CUE】
- 陈柏宇.2009-CANT.BE.HALF【SONY】【WAV+CUE】
- 李明依.1989-小女生【滚石】【WAV+CUE】
- 《李荣浩 新时代创作新人王》[WAV分轨][310MB]
- 《黑鸭子与马头琴 史上最动听草原音乐》[WAV+CUE][320MB]
- 《汽车发烧音乐精选CD18》[FLAC+CUE][7.1G]
- 郑希怡.2004-Perfect.Date【英皇娱乐】【FLAC分轨】
- 群星.1994-宝丽金超级孖宝2CD【宝丽金】【WAV+CUE】