Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. Advanced Operations on Linked Lists (33 points) Implement a function that mer

ID: 3826871 • Letter: 3

Question

3. Advanced Operations on Linked Lists

(33 points) Implement a function that merges (in other words puts them together) two linked lists. It takes as an argument the head of two lists and returns the new head for the joint list. From the new head it should be possible to reach all other nodes in the combined list. The combined list does not need to retain the order of the original lists. Any ordering is allowed after the merge.

typedef int Item;

typedef struct node {

   Item data;

   struct node *next;

} List;

List * merge(List * a, List *b);

Explanation / Answer

typedef int Item;

typedef struct node {
Item data;
struct node *next;
} List;

List * merge(List * a, List *b)
{
// get head of current list
List *temp = a;
if(a == NULL)
return b;
  
// go to last node of the list
while(temp->next != NULL)
{
temp = temp->next;
}
  
// make b's head as next of last node
temp->next = b;
return a;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote