解题思路:
/*
struct RandomListNode {int label;
struct RandomListNode *next, *random;
RandomListNode(int x) :
label(x), next(NULL), random(NULL) {
}
};
*/
class Solution {
public:
RandomListNode* Clone(RandomListNode* pHead)
{
if(!pHead) return NULL;
RandomListNode* tmp;
RandomListNode* t = pHead;
RandomListNode* head;
while(t){
tmp = new RandomListNode(t->label);
tmp->next = t->next;
t->next = tmp;
t = tmp->next;
}
t = pHead;
while(t){
tmp = t->next;
if(t->random) tmp->random = t->random->next;
t = tmp->next;
}
t = pHead;
head = t->next;
while(t->next){
tmp = t->next;
t->next = tmp->next;
t = tmp;
}
return head;
}
};