Enter a complex list with node values in each node, and two pointers, one pointing to the next node, and the other a special pointer to any node.
ClassSolution { Public: voidClonelist (randomlistnode*phead) {Randomlistnode* cur =Phead; Randomlistnode* Temp =NULL; while(cur! =NULL) {Temp=NewRandomlistnode (0); Temp->label = cur->label; Temp->next = cur->Next; Temp->random =NULL; Cur->next =temp; Cur= temp->Next; } } voidGetconnection (randomlistnode*phead) {Randomlistnode* cur =Phead; while(cur! =NULL) { if(Cur->random! =NULL) {cur->next->random = cur->random->Next; } cur= cur->next->Next; }} Randomlistnode* Pickdump (randomlistnode*phead) { if(Phead = = NULL)returnNULL; Randomlistnode* cur =Phead; Randomlistnode*Clonehead; Clonehead= phead->Next; Randomlistnode* Pre =Phead; Randomlistnode* clonepre=Clonehead; Cur= clonehead->Next; while(cur! =NULL) {Pre->next =cur; Clonepre->next = cur->Next; Pre=cur; Clonepre=clonepre->Next; Cur= clonepre->Next; } pre ->next = NULL; Clonepre->next =NULL; returnClonehead; } Randomlistnode* Clone (randomlistnode*phead) { if(Phead = = NULL)returnNULL; Randomlistnode* clonehead=NULL; Clonelist (Phead); Getconnection (Phead); Clonehead=Pickdump (Phead); returnClonehead; }};
My problem is that the end of the link is not over, and the clutter is connected together. So pay attention to the details, including the end!!!!!!!!!!!!!!!!!.
Enter a complex list with node values in each node, and two pointers, one pointing to the next node, and the other a special pointer to any node.