google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: C program in data structure for concatenate two linked list

Monday, April 6, 2015

C program in data structure for concatenate two linked list

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
struct node
{
 int info;
 struct node *link;
}*start1=NULL,*start2;
void main()
{
 struct node *temp,*q;
 int n,i,x;
 clrscr();
 printf("\n First linked list");
 printf("\n Enter How many number:-");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  temp=(struct node*)malloc(sizeof(struct node));
  if(temp==NULL)
  {
   printf("\n Insufficient memory");
   getch();
   exit(0);
  }
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;
  if(start1==NULL)
  {
   start1=temp;
  }
  else
  {
   q=start1;
   while(q->link!=NULL)
   {
     q=q->link;
   }
   q->link=temp;
  }
 }
 printf("\n first list\n");
 q=start1;
 while(q!=NULL)
 {
  printf("\t%d",q->info);
  q=q->link;
 }
 start2=NULL;
 printf("\n Second linked list");
 printf("\n Enter How many number:-");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  temp=(struct node*)malloc(sizeof(struct node));
  if(temp==NULL)
  {
   printf("\n Insufficient memory");
   getch();
   exit(0);
  }
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;
  if(start2==NULL)
  {
   start2=temp;
  }
  else
  {
   q=start2;
   while(q->link!=NULL)
   {
     q=q->link;
   }
   q->link=temp;
  }
 }
 printf("\n second list\n");
 q=start2;
 while(q!=NULL)
 {
  printf("\t%d",q->info);
  q=q->link;
 }

 q=start1;
 while(q->link!=NULL)
 {
      //concatenate two linked list
  q=q->link;
 }
 q->link=start2;
 printf("\n After concatenate linked list\n");
 q=start1;
 while(q!=NULL)
 {
  printf("\t%d",q->info);
  q=q->link;
 }
 getch();
}

शिव भोलेनाथ स्तुति

 जय शिवशंकर, जय गंगाधर, करुणा-कर करतार हरे,   जय कैलाशी, जय अविनाशी, सुखराशि, सुख-सार हरे जय शशि-शेखर, जय डमरू-धर जय-जय प्रेमागार हरे,   जय ...