Vous êtes sur la page 1sur 5

#include<stdio.

h>
#include<conio.h>
struct list
{
int data;
struct list *next;
};
typedef struct list node;
node *head1,*head2;
create1()
{
int ele;
node *ptr,*prev;
while(1)
{
printf("Enter element");
scanf("%d",&ele);
if(ele==-1)
break;
else
{
ptr=(node*)malloc(sizeof(node));
ptr->data=ele;
if(head1==NULL)
prev=head1=ptr;
else

{
prev->next=ptr;
prev=ptr;
}
ptr->next=NULL;
}
}
}
void display1()
{
node *ptr;
ptr=head1;
printf("Elements in lists are:");
while(ptr!=NULL)
{
printf("%d \t",ptr->data);
ptr=ptr->next;
}
}
void create2()
{
int ele;
node *ptr,*prev;
while(1)
{
printf("Enter the elements");

scanf("%d",&ele);
if(ele==-1)
break;
else
{
ptr=(node*)malloc(sizeof(node));
ptr->data=ele;
if(head2==NULL)
prev=head2=ptr;
else
{
prev->next=ptr;
prev=ptr;
}
ptr->next=NULL;
}
}
}
void display2()
{
node *ptr;
ptr=head2;
printf("\nElements are ");
while(ptr!=NULL)
{
printf("%d \t",ptr->data);

ptr=ptr->next;
}
printf("\n");
}
void append()
{
node *p1,*p2;
p1=head1;
p2=head2;
while(p1!=NULL)
{
printf("%d \t",p1->data);
p1=p1->next;
}
p1->next=p2;
while(p2!=NULL)
{
printf("%d \t",p2->data);
p2=p2->next;
}
}
void main()
{
create1();
create2();
display1();

display2();
append();
getch();
}

Vous aimerez peut-être aussi