| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 
 |  #include "Linklist.h"
 ComplexNode* BuyComplexNode(DataType d)
 {
 ComplexNode* node = (ComplexNode *)malloc(sizeof(ComplexNode));
 if (node == NULL){
 perror("Buy Node");
 exit(FILENAME_MAX);
 }
 node->data = d;
 node->next = NULL;
 node->random = NULL;
 return node;
 }
 
 void PrintComplexList(ComplexNode* plist)
 {
 assert(plist);
 while (plist)
 {
 printf("%d : ", plist->data);
 if (plist->random != NULL){
 printf("(%d)-->", plist->random->data);
 }
 else{
 printf("(NULL)-->");
 }
 plist = plist->next;
 }
 printf("Over !\n");
 }
 
 ComplexNode* CopyComplexList(ComplexNode* plist)
 {
 ComplexNode* cur = NULL;
 ComplexNode* tmp = NULL;
 ComplexNode* head = NULL;
 assert(plist);
 cur = plist;
 
 while (cur != NULL){
 tmp = BuyComplexNode(cur->data);
 tmp->next = cur->next;
 cur->next = tmp;
 cur = tmp->next;
 }
 cur = plist;
 tmp = cur->next;
 
 while (cur != NULL){
 if (cur->random != NULL){
 tmp->random = cur->random->next;
 }
 cur = tmp->next;
 
 if (cur == NULL){
 break;
 }
 tmp=cur->next;
 }
 cur = plist;
 tmp = cur->next;
 head = tmp;
 
 while (cur != NULL)
 {
 cur->next = tmp->next;
 cur = cur->next;
 
 if (cur == NULL){
 break;
 }
 tmp->next = cur->next;
 tmp = tmp->next;
 }
 
 return head;
 }
 
 |