Guest User

Untitled

a guest
Apr 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. typedef struct node {
  2. char *first;
  3. char *last;
  4. long number;
  5. struct node *nextFirst;
  6. struct node *nextLast;
  7. } Node;
  8.  
  9. typedef struct mlist {
  10. Node *headFirstName;
  11. Node *headLastName;
  12. } MultiLinkedList;
  13.  
  14. MultiLinkedList *add(MultiLinkedList *list, char *first, char *last, long num) {
  15. // allocate a new node
  16. Node *newNode = malloc ( sizeof(Node) );
  17. newNode->first = malloc ( strlen(first) + 1 );
  18. strcpy(newNode->first, first);
  19. newNode->last = malloc ( strlen(last) + 1 );
  20. strcpy(newNode->last, last);
  21. newNode->number = num;
  22. // add this new node at the head of the "byFirst" list
  23. newNode->nextFirst = list->headFirstName;
  24. list->headFirstName = newNode;
  25. // add this new node at the head of the "byLast" list
  26. newNode->nextLast = list->headLastName;
  27. list->headLastName = newNode;
  28. // return the multi-list object with updated head pointers
  29. return list;
  30. }
Add Comment
Please, Sign In to add comment