|
|
@ -117,11 +117,18 @@ public class Code04_CopyListWithRandom {
|
|
|
|
head.next.next.next.next.rand = null; // 5 -> null
|
|
|
|
head.next.next.next.next.rand = null; // 5 -> null
|
|
|
|
head.next.next.next.next.next.rand = head.next.next.next; // 6 -> 4
|
|
|
|
head.next.next.next.next.next.rand = head.next.next.next; // 6 -> 4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("原始链表:");
|
|
|
|
printRandLinkedList(head);
|
|
|
|
printRandLinkedList(head);
|
|
|
|
|
|
|
|
System.out.println("=========================");
|
|
|
|
res1 = copyListWithRand1(head);
|
|
|
|
res1 = copyListWithRand1(head);
|
|
|
|
|
|
|
|
System.out.println("方法一的拷贝链表:");
|
|
|
|
printRandLinkedList(res1);
|
|
|
|
printRandLinkedList(res1);
|
|
|
|
|
|
|
|
System.out.println("=========================");
|
|
|
|
res2 = copyListWithRand2(head);
|
|
|
|
res2 = copyListWithRand2(head);
|
|
|
|
|
|
|
|
System.out.println("方法二的拷贝链表:");
|
|
|
|
printRandLinkedList(res2);
|
|
|
|
printRandLinkedList(res2);
|
|
|
|
|
|
|
|
System.out.println("=========================");
|
|
|
|
|
|
|
|
System.out.println("经历方法二拷贝之后的原始链表:");
|
|
|
|
printRandLinkedList(head);
|
|
|
|
printRandLinkedList(head);
|
|
|
|
System.out.println("=========================");
|
|
|
|
System.out.println("=========================");
|
|
|
|
|
|
|
|
|
|
|
|