Solution:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* next;
};
struct node* head1=NULL;
struct node* head2=NULL;
void traverse(struct node** head);
struct node* cn()
{
struct node * n;
n=(struct node *)malloc(sizeof(struct node));
return(n);
}
void createnode(struct node **head,int n)
{
int x,i=1;
struct node * newnode,*temp;
printf("Enter elemets for linked list :\n");
for(i=1;i<=n;i++)
{
scanf("%d",&x);
if(*head==NULL)
{
newnode=cn();
newnode->data=x;
newnode->next=NULL;
*head=newnode;
temp=*head;
}
else
{
newnode=cn();
newnode->data=x;
newnode->next=NULL;
temp->next=newnode;
temp=newnode;
}
}
}
void concatination()
{
int i;
struct node *temp1,*temp2;
temp1=head1;
temp2=head2;
printf("\nConcatenated Linked List :\n");
while(temp1->next!=NULL)
{
temp1=temp1->next;
}
temp1->next=head2;
traverse(&head1);
}
void traverse(struct node** head) //Function to traverse Linked list.
{
struct node * temp3;
temp3=*head;
while(temp3!=NULL)
{
printf("%d\n",temp3->data);
temp3=temp3->next;
}
}
int main()
{
int h1,h2,choice;
printf("\nEnter size of first linked list :\n");
scanf("%d",&h1);
createnode(&head1,h1);
printf("\nEnter size of second node :\n");
scanf("%d",&h2);
createnode(&head2,h2);
concatination();
}
0 Comments