| OCR Text |
Show struct list { /* a linked list data structure */ struct list *next; /* a pointer to the next element */ ... /* the rest of the structure */ } ; /* copy the list from the executor to the director: */ /* parameter is the name of the head pointer */ /* of the original list in the executor, */ /* the result is the address of the head pointer */ /* of the copy in the director */ struct list *copy_list (char *s) { struct list *p,*head; /* get the address of the head of the list */ head = dsgetsym(s); /* copy the value of the head */ dsgetmem(head,sizeof(head),&head); /* if the list is empty, return */ if (head == NULL) return(NULL); /* allocate the space, copy the element, */ /* obtain the pointer */ p = head = dsgetptr(head,sizeof(struct list)); /* while there are more elements */ while (p->next != NULL) { /* copy the next element */ p->next = dsgetptr(p->next,sizeof(struct list)); /* advance the pointer */ p = p->next; } " /* return the result */ return(head); } ; Figure 4.13. A Director to Copy a Linked List |