MERGING LINK LIST

-------------------------------------------------

#include
#include
#include
#include
struct node{
int data;
struct node *link;
};
void main()
{
struct node *head=NULL,*ptr,*temp,*head2=NULL,*temp2;
int i,n;
clrscr();
printf("====================================================\n");
printf("merging of link list program\n");
printf("enter the size of link list\n");
scanf("%d",&n);
for(i=0;i {
       temp=(struct node*)malloc(sizeof(struct node));
       printf("enter the data in new node\n");
       scanf("%d",&temp->data);
       temp->link=NULL;
if(head==NULL)
  head=temp;
  else
  {
ptr=head;
while(ptr->link!=NULL)
ptr=ptr->link;
ptr->link=temp;
}}
printf("link list 1st\n ")
ptr=head;
while(ptr!=NULL)
{
       printf("\t%d",ptr->data);
       ptr=ptr->link;
}
printf("\n=====================================================\n");
printf("\nenter the size of new link list\n");
scanf("%d",&n);
for(i=0;i {
       temp2=(struct node*)malloc(sizeof(struct node));
       printf("enter the data in new node\n");
       scanf("%d",&temp2->data);
       temp2->link=NULL;
if(head2==NULL)
  head2=temp2;
  else
  {
ptr=head2;
while(ptr->link!=NULL)
ptr=ptr->link;
ptr->link=temp2;
}}
printf("link list 2nd");
ptr=head2;
while(ptr!=NULL)
{
       printf("\t%d",ptr->data);
       ptr=ptr->link;
}

printf("\nafter merging the link list\n");
    temp->link=head2;
    ptr=head;
    while(ptr!=NULL)
    {
    printf("\t%d",ptr->data);
       ptr=ptr->link;

}

getch();
}