#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node1
{
struct node1 *link;
int info;
};
struct node1 *start1=NULL;
struct node2
{
struct node2 *link;
int info;
};
struct node2 *start2=NULL;
struct merge
{
struct merge *link;
int info;
};
struct merge *start=NULL;
void main()
{
int ch;
while(ch!=5)
{
clrscr();
printf("1 for insert in first linklist\n");
printf("2 for insert in second linklist\n");
printf("3 for display first & second linklist\n");
printf("4 for merge linklist\n");
printf("5 for exit\n");
printf("\nEnter ur choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: insert1();
break;
case 2: insert2();
break;
case 3: display();
break;
case 4: merge_dis();
break;
case 5: break;
}
}
}
merge_dis()
{
struct node1 *temp1;
struct node2 *temp2;
struct merge *temp,*temp10;
int t=0;
for(temp1=start1,temp2=start2;temp1!=NULL,temp2!=NULL;temp1=temp1->link,temp2=temp2->link)
{
if(temp1->info>=temp2->info)
{
if(temp1->info=temp2->info)
{
temp1++;
}
t=temp2->info;
temp->info=t;
temp->link=start;
start= temp;
temp2++;
}
else
{
t=temp1->info;
temp->info=t;
temp->link=start;
start=temp;
temp1++;
}
}
printf("\nThe Information of Merge linklist\n");
for(temp10=start;temp10!=NULL;temp10=temp10->link)
{
printf("%d ",temp10->info);
}
getch();
}
insert1()
{
struct node1 *new;
new=(struct node1 *)malloc(sizeof(struct node1));
printf("Enter the info");
scanf("%d",&new->info);
new->link=start1;
start1=new;
}
insert2()
{
struct node2 *new;
new=(struct node2 *)malloc(sizeof(struct node2));
printf("Enter the info");
scanf("%d",&new->info);
new->link=start2;
start2=new;
}
display()
{
struct node1 *temp;
struct node2 *temp1;
printf("\nThe Information of First linklist\n");
for(temp=start1;temp!=NULL;temp=temp->link)
{
printf("%d ",temp->info);
}
printf("\nThe Information of Second linklist\n");
for(temp1=start2;temp1!=NULL;temp1=temp1->link)
{
printf("%d ",temp1->info);
}
getch();
}