Hi, I was given an assignment to write two functions.
The first function is rather easy and I think I have it. However, the second function is an ADT function called MergeList, which merges two lists using a linked list implementation with a dummy node. The function returns the new list.
I realize that I must traverse L1 and see when the link is NULL then make the link to (L2->link)->link. Is this correct? Does my code seem to be in order so far? Can anyone offer any suggestions or corrections? Thanks so much. As always, your help is GREATLY appreciated!!!Code:List MergeLists(List L1, List L20 { list newlist; newlist = (List)malloc(sizeof(listCDT)); if(!newlist) { printf("Memory allocation error!\n"); exit(1); } newlist->size = 0; newlist->link = (listnode*)malloc(sizeof(listnode)); if (!newlist) { printf("Memory allocation error!\n"); exit(1); } (newlist->link)->link = (L1->link)->link; . . . return newlist; }
Thanks,
Jacob