You are on page 1of 3

#include<stdio.

h>
#include<stdlib.h>
struct node1
{
int data1;
struct node1 *next1;
}*head1;
struct node2
{
int data2;
struct node2 *next2;
}*head2;
int main()
{
int i,n1,n2,d1,d2;
struct node1 *newnode1,*temp1;
struct node2 *newnode2,*temp2;
printf("enter the size of list-1:\n");
scanf("%d",&n1);
printf("enter the size of list-2:\n");
scanf("%d",&n2);
head1=(struct node1*)malloc(sizeof(struct node1));
printf("enter the elements of the first list:\n");
scanf("%d",&d1);
head1->data1=d1;
head1->next1=NULL;
temp1=head1;
for(i=1;i<n1;i++)
{
newnode1=(struct node1*)malloc(sizeof(struct node1));
scanf("%d",&d1);
newnode1->data1=d1;
newnode1->next1=NULL;
temp1->next1=newnode1;
temp1=temp1->next1;
}
head2=(struct node2*)malloc(sizeof(struct node2));
printf("enter the elements of the second list:\n");
scanf("%d",&d2);
head2->data2=d2;
head2->next2=NULL;
temp2=head2;
for(i=1;i<n2;i++)
{
newnode2=(struct node2*)malloc(sizeof(struct node2));
scanf("%d",&d2);
newnode2->data2=d2;
newnode2->next2=NULL;
temp2->next2=newnode2;
temp2=temp2->next2;
}
struct node1 *t1;
struct node2 *t2;
if(head1==NULL)
{
printf("the list 1 is empty");
}
else
{
t1=head1;
printf("elements in list1:\n");
while(t1!=NULL)
{
printf("%d ",t1->data1);
t1=t1->next1;
}
}
if(head2==NULL)
{
printf("the list 2 is empty");
}
else
{
t2=head2;
printf("\nelements in list 2 are:\n");
while(t2!=NULL)
{
printf("%d ",t2->data2);
t2=t2->next2;
}
}
struct node1 *s1;
struct node2 *s2;
s1=head1;
s2=head2;
int f=0,g=0;
printf("\nthe elements of list-3 are:\n");
while(s1!=NULL)
{
if(f%2!=0)
{
printf("%d",s1->data1);
s1=s1->next1;
f+=1;
}
else
{
printf(" ");
}
}
while(s2!=NULL)
{
if(g%2==0)
{
printf("%d\n",s2->data2);
s2=s2->next2;
g=g+1;
}
else
{
printf(" ");
}
}
return 0;
}

You might also like