Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct node {
- char *first;
- char *last;
- long number;
- struct node *nextFirst;
- struct node *nextLast;
- } Node;
- typedef struct mlist {
- Node *headFirstName;
- Node *headLastName;
- } MultiLinkedList;
- MultiLinkedList *add(MultiLinkedList *list, char *first, char *last, long num) {
- // allocate a new node
- Node *newNode = malloc ( sizeof(Node) );
- newNode->first = malloc ( strlen(first) + 1 );
- strcpy(newNode->first, first);
- newNode->last = malloc ( strlen(last) + 1 );
- strcpy(newNode->last, last);
- newNode->number = num;
- // add this new node at the head of the "byFirst" list
- newNode->nextFirst = list->headFirstName;
- list->headFirstName = newNode;
- // add this new node at the head of the "byLast" list
- newNode->nextLast = list->headLastName;
- list->headLastName = newNode;
- // return the multi-list object with updated head pointers
- return list;
- }
Add Comment
Please, Sign In to add comment