Tuesday, March 31, 2015

Mege in order list3 list1 list 2

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
 int data;
struct node * next;
};
void append(struct node **q)
{
 struct node *temp;
 temp=*q;
 if(temp==NULL)
{
*q=(struct node *)malloc(sizeof(struct node));
printf("\nenter the data");
scanf("%d",&(*q)->data);
(*q)->next=NULL;
}
else
{
while(temp->next!=NULL)
  temp=temp->next;

temp->next=(struct node *)malloc(sizeof(struct node));
temp=temp->next;

printf("\nenter the data");
scanf("%d",&temp->data);
temp->next=NULL'
  }
}


void merge(struct node **q,struct node **q2,struct node *q3)
{
 struct node *temp,*t,*t1;
temp=*q;
t=*q2;
t1=*q3;
p=temp; //list 1
 while(temp->next!=NULL)
 temp=temp->next;
 temp->next=t;

while(t1->next!=NULL)
  t1=t1->next;
 t1->next=p;

}

void main()
{
 struct node *start,*start2;
 start=NULL; //empty list1
start2=NULL; //empty list 2
start3=NULL; //empty list 3
  printf("\nenter the first list : ")
 append(&start);
 append(&start);
 append(&start);
printf("\now the list is :");
display(start);
printf("\nenter the second list :");
append(&start2);
 append(&start2);
 append(&start2);
printf('\now the list is :')
display(start2);
printf("\nenter the Third list :");
append(&start3);
 append(&start3);
 append(&start3);
printf('\now the list is :')
display(start3);
 merge(&start,&start2);
prinf("\nlist in order List3 list1 list 2");
display(&start3);
}

No comments:

Post a Comment