I want to make two linked lists and want to merge them in sorted order.I tried to take them into a function named "merge(link1,link2)",but i don't know that how to give the reference of linked lists to the function.
#include<iostream>
#include<malloc.h>
using namespace std;
struct node
{
int info;
node *next;
};
node *start1=NULL;
node *start2=NULL;
void link1(int x)
{
node *temp=(node *)malloc(sizeof(node));
node *t;
temp->info=x;
temp->next=NULL;
if(start1==NULL)
start1=temp;
else
{
t=start1;
while(t->next!=0)
{
t=t->next;
}
t->next=temp;
}
}
void link2(int x)
{
node *temp=(node *)malloc(sizeof(node));
node *t;
temp->info=x;
temp->next=NULL;
if(start2==NULL)
start2=temp;
else
{
t=start2;
while(t->next!=0)
{
t=t->next;
}
t->next=temp;
}
}
void merge(link1,link2)
{
//merge function
}
int main()
{
link1(1);
link1(2);
disp1();
cout<<"\n";
link2(3);
link2(4);
disp2();
merge(link 1,link2); //this is problem how to give reference of inked lists here.
}
Output: expected output after merge function is 1->2->3->4.