hi i need help with linked list. so iam trying to mege two linked list together. i got all to working but my meger method dont work.

lets say age of List_A = 1, 2, 3; and List_B = 2, 4, 5, 6; after meger method i should get 1,2,2,3,4,5.

also dont i dont want to use recursion and i want to keep my structs same.

struct List_A
{
    char name[10];
    int age;
    struct List_A *next;
};
struct List_A *head1;

struct List_B
{
    char name[10];
    int age;
    struct List_B *next;
};
struct List_B *head2;



int main(void)
{
// main is finish
return 0;
}
void insert(char name[])
{
//insert method is done
}


void merge ()
{
  struct List_A *cur_node_A = head1;
  struct List_B *cur_node_B = head2;

  while(cur_node_A != NULL && cur_node_B != NULL)
  {
   if(cur_node_A->age > cur_node_B->age)
   {
   }
   else
   {
   }
   cur_node_A = cur_node_A->next;
   cur_node_B = cur_node_B->next;
  }
}

a simple solution would be to insert new nodes in a linked list where the nodes that will be created would resemble the nodes present in the second linked list

This article has been dead for over six months. Start a new discussion instead.