Copying Linked Lists with Random Pointers

两个方法:
方法一:

1.不考虑随机指针的情况下复制链表;

2.在复制过程中建立一个以原链表节点地址为key,相应的复制链表节点地址为value的hash;

3.遍历原链表和新链表,得到原链表随机指针值,并复制给新链表。

方法二:

1.忽略随机指针值复制链表第n个节点并插入到第n个节点与第n+1个节点之间,以此为方式修改链表直到链表尾。

2.利用链表节点next指针指向节点的的拷贝这一已知,使用如下语句:

 srcCurrent->next->random = srcCurrent->random->next;

3.分开链表

srcCurrent->next = srcCurrent->next->next;
cpyCurrent->next = cpyCurrent->next->next;

  

Copying Linked Lists with Random Pointers的更多相关文章

  1. [Linked List]Intersection of Two Linked Lists

    Total Accepted: 53721 Total Submissions: 180705 Difficulty: Easy Write a program to find the node at ...

  2. LeetCode之“链表”:Intersection of Two Linked Lists

    此题扩展:链表有环,如何判断相交? 参考资料: 编程判断两个链表是否相交 面试精选:链表问题集锦 题目链接 题目要求: Write a program to find the node at whic ...

  3. 2016.5.24——Intersection of Two Linked Lists

    Intersection of Two Linked Lists 本题收获: 1.链表的输入输出 2.交叉链表:这个链表可以有交叉点,只要前一个节点的的->next相同即可. 题目:Inters ...

  4. LeetCode: Intersection of Two Linked Lists 解题报告

    Intersection of Two Linked Lists Write a program to find the node at which the intersection of two s ...

  5. [LeetCode] 160. Intersection of Two Linked Lists 求两个链表的交集

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  6. [LeetCode] Intersection of Two Linked Lists 求两个链表的交点

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  7. 【leetcode】Intersection of Two Linked Lists

    题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...

  8. [LintCode] Intersection of Two Linked Lists 求两个链表的交点

    Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...

  9. Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

随机推荐

  1. 能发送http请求(get,post)的工具

    能发送http请求(get,post)的工具, 1.  fiddler 前端自己模拟发送请求 2.  其他 链接:https://www.zhihu.com/question/20367546/ans ...

  2. 用FlexSlider制作支付宝2013版幻灯片演示插件

    flexslider制作支付宝2013版幻灯片精美特效,一款非常不错的jQuery特效源码可在下面地址或去源码搜藏网下载适用浏览器:IE8.360.FireFox.Chrome.Safari.Oper ...

  3. Installing the .NET Framework 4.5, 4.5.1

    This article provides links for installing the .NET Framework 4.5 and 4.5.1 on your computer.  If yo ...

  4. 父页面iframe自动适应子页面的宽高度

    <script type="text/javascript"> function load(){ parent.document.getElementById(&quo ...

  5. Dom4j解析Xml文件,Dom4j创建Xml文件

    Dom4j解析Xml文件,Dom4j创建Xml文件 >>>>>>>>>>>>>>>>>>&g ...

  6. return与finally

    当return遇到了finally,先标记return的值,然后执行finally,当finally修改了return的值,那么执行finally后,传递最后一次return的值,若finally没有 ...

  7. guid 新建

    var guid = Guid.NewGuid();foreach (var i in new string[] { "P", "N", "B&quo ...

  8. <script runat=server>、<%%>和<%#%>的区别

    ①<script runat="server">代码段与<%%>内联代码段的区别 在asp.net页面的aspx文件中允许使用<script runa ...

  9. [Jquery] jQuery.cookie帮助类 (转载)

    /** * Cookie plugin * * Copyright (c) [url=http://sufei.cnblogs.com/]http://sufei.cnblogs.com[/url] ...

  10. .NET设计模式(4):建造者模式(Builder Pattern)

    ):建造者模式(Builder Pattern)    .建造者模式的使用使得产品的内部表象可以独立的变化.使用建造者模式可以使客户端不必知道产品内部组成的细节. 2.每一个Builder都相对独立, ...