标签:
class Solution { public: RandomListNode* Clone(RandomListNode* pHead) { if(pHead==NULL) return NULL; RandomListNode * p=pHead; while(p!=NULL) { RandomListNode *tmp= new RandomListNode(p->label); tmp->next=p->next; tmp->random=p->random; p->next=tmp; p=p->next->next; } p=pHead; while(p!=NULL&&p->next!=NULL) { if(p->next->random) p->next->random=p->next->random->next; p=p->next->next; } p=pHead; RandomListNode *cp=pHead->next; RandomListNode * pn=pHead->next; while(p!=NULL && pn!=NULL&&pn->next&&pn->next->next) { p->next=pn->next; pn->next=pn->next->next; p=p->next; pn=pn->next; } p->next=NULL; return cp; } };
标签:
原文地址:http://www.cnblogs.com/daocaorenblog/p/5373641.html