We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,363 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

working with 2 linked lists -_-;

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;
  }
}
2
Contributors
1
Reply
8 Hours
Discussion Span
1 Year Ago
Last Updated
2
Views
hwoarang69
Posting Pro
569 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 7

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

zeroliken
Nearly a Posting Virtuoso
1,346 posts since Nov 2011
Reputation Points: 214
Solved Threads: 205
Skill Endorsements: 14

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0566 seconds using 2.71MB