| 
                                                
                                                    PROGRAM TO CONCATENATE TWO LINEAR LINKED LISTS
                                                
                                                
 /************************************************/
 /*PROGRAM TO CONCATENATE TWO LINEAR LINKED LISTS*/
 /************************************************/
 
 #include < stdio.h>
 #include < conio.h>
 #include < malloc.h>
 #include < process.h>
 #include < ctype.h>
 
 struct linear_list
 {
 int info;
 struct linear_list *next;
 }*start,*start1,*newnode,*ptr;
 
 void main()
 {
 int item;
 int i;
 char ch;
 clrscr();
 printf("\nCreate first linked list:\n");
 newnode=(struct linear_list*)malloc(sizeof(struct linear_list));
 start=newnode;
 do
 {
 printf("\nEnter data: ");
 scanf("%d",&item);
 newnode->info=item;
 printf("\nDo you want to create another node:(y/n)");
 fflush(stdin);
 scanf("%c",&ch);
 if(tolower(ch)=='y')
 {
 newnode->next=(struct linear_list*)malloc(sizeof(struct linear_list));
 newnode=newnode->next;
 }
 else
 {
 newnode->next=NULL;
 }
 }while(tolower(ch)!='n');
 
 clrscr();
 printf("\nCreate second linked list:\n");
 newnode=(struct linear_list*)malloc(sizeof(struct linear_list));
 start1=newnode;
 do
 {
 printf("\nEnter data: ");
 scanf("%d",&item);
 newnode->info=item;
 printf("\nDo you want to create another node:(y/n)");
 fflush(stdin);
 scanf("%c",&ch);
 if(tolower(ch)=='y')
 {
 newnode->next=(struct linear_list*)malloc(sizeof(struct linear_list));
 newnode=newnode->next;
 }
 else
 {
 newnode->next=NULL;
 }
 }while(tolower(ch)!='n');
 
 ptr=start;
 while(ptr->next!=NULL)
 {
 ptr=ptr->next;
 }
 ptr->next=start1;
 
 printf(“\n Concatenated Linked Lists are:\n”);
 ptr=start;
 i=1;
 while(ptr!=NULL)
 {
 printf("\nNode %d : %d",i,ptr->info);
 ptr=ptr->next;
 i++;
 }
 getch();
 }
 
 
 
 
 http://
 http://
 
 Contributed by:
 Rohit kakria
 I am software developer
 
 Resourse address on xpode.com
 http://www.xpode.com/Print.aspx?Articleid=365
 Click here to  go on website  |