# 剑指offer：复杂链表的复制

﻿﻿题目描述：输入一个复杂链表，每个节点中有节点值，以及两个指针，一个指向下一个节点，另一个特殊指针指向任意一个节点（可能为NULL），求输出复杂链表的拷贝（返回拷贝链表的头结点即可）

#include<iostream>
#include<map>

using namespace std;

struct RandomListNode {
int label;
struct RandomListNode *next, *random;
RandomListNode(int x) :
label(x), next(NULL), random(NULL) {
}
};

class Solution {
public:
{
return NULL;
RandomListNode * res = new RandomListNode(pHead->label);
RandomListNode * tmp = res;
map<RandomListNode *, RandomListNode *> m;
m[p] = res;
//tmp = tmp->next;
p = p->next;
while (p)
{
//tmp = new RandomListNode(p->label);
//m[p] = tmp;
//tmp = tmp->next;
//p = p->next;
RandomListNode * newNode = new RandomListNode(p->label);
tmp->next = newNode;
tmp = newNode;
m[p] = tmp;
p = p->next;
}
tmp = res;
while (p)
{
if (p->random)
tmp->random = m.find(p->random)->second;
tmp = tmp->next;
p = p->next;
}
return res;
}
};

{
{
}
}

int main()
{
RandomListNode * p1 = new RandomListNode(1);
RandomListNode * p2 = new RandomListNode(2);
RandomListNode * p3 = new RandomListNode(3);
RandomListNode * p4 = new RandomListNode(4);
RandomListNode * p5 = new RandomListNode(5);
p1->next = p2; p2->next = p3;
p3->next = p4; p4->next = p5;
p5->next = NULL;
p1->random = p3; p2->random = p4;
p3->random = NULL; p4->random = p2;
p5->random = NULL;

Solution s;
}