Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. struct link {
  2. char * name;
  3. struct link *next;
  4. };
  5.  
  6.  
  7. struct list{
  8. struct link *first;
  9. struct link *last;
  10. };
  11.  
  12.  
  13.  
  14. struct list *list_new(){
  15. struct list *n = calloc(1, sizeof(struct list));
  16. return n;
  17. };
  18.  
  19.  
  20.  
  21.  
  22. struct list* copyList(struct list*list){
  23. struct list*new = list_new();
  24. struct link *current = list -> first;
  25. struct link *newCurrent = new -> first;
  26. struct link *p;
  27. if(current == NULL)
  28. return NULL;
  29.  
  30.  
  31. newCurrent = malloc(sizeof(struct link));
  32. newCurrent = p;
  33.  
  34. while (current != NULL) {
  35. p ->shelfName = strdup((char*)current -> shelfName);
  36. p->next = malloc(sizeof(struct link));
  37. p = p->next;
  38. current = current->next;
  39. }
  40.  
  41. return new;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement