1.11M Members

working with 2 linked lists -_-;

 
0
 

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;
  }
}
 
0
 

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

Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article