//concatination of two single linked list
#include
#include
#include
#include
struct linkedlist
{
int info;
struct linkedlist *next;
};
typedef struct linkedlist NODE;
NODE * create(NODE *);
void display(NODE *);
NODE * concatinate(NODE *,NODE *);
NODE *head;
NODE * node1,* node2;
NODE start;
void main()
{
clrscr();
node1=(NODE *)malloc(sizeof(NODE));
printf("\n create first linked list \n");
node1=create(node1);
printf("\n first linked list is \n");
display(node1);
printf("\n create second linked list \n");
node2=(NODE*)malloc(sizeof(NODE));
node2=create(node2);
printf("\n second linked list is \n");
display(node2);
node1=concatinate(node1,node2);
printf("\n after concatination list is \n");
display(node1);
getch();
}
NODE *create(NODE * list)
{
int a;
printf("\n enter a number to add (at end press -0)-->");
scanf("%d",&a);
if(a==-0)
{
list->info=a;
list->next=NULL;
return (list);
}
else
{
list->info= a;
list->next=(NODE *)malloc(sizeof(NODE));
create(list->next);
}
return(list);
}
void display (NODE *node)
{
printf("\n ROOT->");
while(node->next!=NULL)
{
printf("%d->",node->info);
node=node->next;
}
printf("NULL");
}
NODE *concatinate(NODE * list1, NODE * list2)
{
NODE *temp=list1;
while(list1->next->next!=NULL)
{
list1=list1->next;
}
if(list1->next->next==NULL)
{
list1->next=list2;
}
list1=temp;
return(list1);
}
#include
#include
#include
#include
struct linkedlist
{
int info;
struct linkedlist *next;
};
typedef struct linkedlist NODE;
NODE * create(NODE *);
void display(NODE *);
NODE * concatinate(NODE *,NODE *);
NODE *head;
NODE * node1,* node2;
NODE start;
void main()
{
clrscr();
node1=(NODE *)malloc(sizeof(NODE));
printf("\n create first linked list \n");
node1=create(node1);
printf("\n first linked list is \n");
display(node1);
printf("\n create second linked list \n");
node2=(NODE*)malloc(sizeof(NODE));
node2=create(node2);
printf("\n second linked list is \n");
display(node2);
node1=concatinate(node1,node2);
printf("\n after concatination list is \n");
display(node1);
getch();
}
NODE *create(NODE * list)
{
int a;
printf("\n enter a number to add (at end press -0)-->");
scanf("%d",&a);
if(a==-0)
{
list->info=a;
list->next=NULL;
return (list);
}
else
{
list->info= a;
list->next=(NODE *)malloc(sizeof(NODE));
create(list->next);
}
return(list);
}
void display (NODE *node)
{
printf("\n ROOT->");
while(node->next!=NULL)
{
printf("%d->",node->info);
node=node->next;
}
printf("NULL");
}
NODE *concatinate(NODE * list1, NODE * list2)
{
NODE *temp=list1;
while(list1->next->next!=NULL)
{
list1=list1->next;
}
if(list1->next->next==NULL)
{
list1->next=list2;
}
list1=temp;
return(list1);
}
6:53 AM |
Category: |
0
comments