资讯专栏INFORMATION COLUMN

js实现基本的链表功能

CarterLi / 381人阅读

function Lian(data,pre,next){
    this.data = data;
    this.preNode = pre;
    if(this.preNode ){
      pre.nextNode = this;
    }
    this.nextNode = next;
}
//输入链表
 Lian.prototype.aaa = function(){

       if(this.nextNode){
              return this.data.name + this.nextNode.aaa();
         }else{
              return this.data.name;
          }
    };
 //插入节点
 Lian.prototype.bbb = function(node){
     if(this.nextNode && this.nextNode.preNode){
         this.nextNode.preNode = node;
     }
   node.nextNode = this.nextNode;
     node.preNode = this;
   this.nextNode = node;
 };
//删除节点
 Lian.prototype.ccc = function(){
        this.nextNode.preNode = this.preNode;
        this.preNode.nextNode = this.nextNode;
    };
var q = new Lian({"name": "1"}, null, null);
var w = new Lian({"name": "2"}, q, null);
var e = new Lian({"name": "3"}, w, null);
 var Head = q;
 console.log(Head.aaa());

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/87311.html

相关文章

  • Leetcode:刷完31道链表题的一点总结

    摘要:既然说到地址空间了就顺带说一下上面环形链表这道题的另一种很的解法吧。介绍完常规操作链表的一些基本知识点后,现在回到快慢指针。   前几天第一次在 Segmentfault 发文—JavaScript:十大排序的算法思路和代码实现,发现大家似乎挺喜欢算法的,所以今天再分享一篇前两个星期写的 Leetcode 刷题总结,希望对大家能有所帮助。   本文首发于我的blog 前言   今天终于...

    DevTalking 评论0 收藏0
  • 用 JavaScript 实现链表操作 - 08 Remove Duplicates

    摘要:递归版本尾递归很多递归没办法自然的写成尾递归,本质原因是无法在多次递归过程中维护共有的变量,这也是循环的优势所在。这是因为虽然用的,但并没有开启尾递归优化。 TL;DR 为一个已排序的链表去重,考虑到很长的链表,需要尾调用优化。系列目录见 前言和目录 。 需求 实现一个 removeDuplicates() 函数,给定一个升序排列过的链表,去除链表中重复的元素,并返回修改后的链表。理想...

    Me_Kun 评论0 收藏0
  • 《算法》第一章学习笔记js实现

    摘要:算法第一章学习笔记实现更多内容目标总结本书主要内容,相应算法使用来模仿实现在计算机科学领域,我们用算法这个词来描述一种有限确定有效的并适合用计算机程序来实现的解决问题的方法。 《算法》第一章学习笔记js实现 更多内容 目标:总结本书主要内容,相应算法使用js来模仿实现 在计算机科学领域,我们用算法这个词来描述一种有限、确定、有效的并适合用计算机程序来实现的解决问题的方法。我们关注的大多...

    baishancloud 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<