THe foll is a part of a prg i have to append one dummy list to a original list at destination in the original list .So plz help me
i am a new user so sorry for any mistalke
Here is the code :
#include<stdio.h>
#include<conio.h>
struct node
{
struct node *prev,*next;
char line[20];
};
void copy(struct node **,int start,int end,int desti);
void Append(struct node **, char *);
void Appendll(struct node **, char *);
void Display(struct node **);
void main()
{
struct node *head=NULL;
int ch,start,end,desti;
char line[20],temp[3];
clrscr();
while(1)
{ printf("Enter your choice: ");
scanf("%d",&ch);
if(ch==1)
{
printf("Enter the data in the first ll ");
scanf("%s",line);
Append(&head,line);
}
else
if(ch==2)
{
Display(&head);
}
else
if(ch==3)
{
printf("Enter the start end and destination ");
scanf("%d %d %d",&start,&end,&desti);
copy(&head,start,end,desti);
}
else
if(ch==0)
{
exit(0);
}
}
}
void Append(struct node **list, char line[])
{
struct node *nn=NULL;
char data[20];
nn=(struct node *)malloc (sizeof(struct node));
strcpy(nn->line,line);
nn->next=NULL;
if(*list==NULL)
{
nn->prev=NULL;
*list=nn;
}
else
{
struct node *t=*list;
while(t->next!=NULL)
t=t->next;
nn->prev=t;
t->next=nn;
}
}
void Appendll(struct node **dummy, char line[])
{
struct node *newnode=NULL;
newnode=(struct node *)malloc (sizeof(struct node));
strcpy(newnode->line,line);
newnode->next=newnode->prev=NULL;
if(*dummy==NULL)
{
newnode->prev=NULL;
*dummy=newnode;
}
else
{
struct node *temp=*dummy;
while(temp->next!=NULL)
temp=temp->next;
newnode->prev=temp;
temp->next=newnode;
}
}
void Display(struct node **head)
{
struct node *temp=*head;
int i;
if(temp==NULL)
{
printf("Empty");
return;
}
else
{
printf("\n\t\t");
do
{
printf("\n%s ",temp->line);
temp = temp->next;
}
while (temp!=NULL);
printf("NULL\n\n");
}
}
void copy(struct node **head,int start,int end,int desti)
{
struct node *s=NULL,*dummy=NULL,*t=NULL;
int i;
char data[20];
for(i=1,s=*head;i<=start;i++)
s=s->next;
//copying the data into dummy link list
for(i=start;i<=end;i++)
{
strcpy(data,s->line);
Appendll(dummy,data);
}
printf("Dummmy");
Display(dummy);
//appending that dummy list to original one at destination
for(i=1,s=*head;i<=desti;i++)
s=s->next;
// desti
//head-> 1 2 3 4 5 s->=6= 7
// dummy ->=1 2 3 4<-t NULL
if(s->next!=NULL)
{
for(t=dummy;t!=NULL;t=t->next);
s->next->prev=t;
t->next=s->next;
s->next=dummy;
dummy->prev=s;
}
Display(head);
}