1,105,402 Community Members

working with 2 linked lists -_-;

Member Avatar
hwoarang69
Posting Pro
572 posts since Feb 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 9 [?]
 
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;
  }
}
Member Avatar
zeroliken
Nearly a Posting Virtuoso
1,222 posts since Nov 2011
Reputation Points: 79 [?]
Q&As Helped to Solve: 216 [?]
Skill Endorsements: 15 [?]
 
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

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