#include<stdio.h>
#include<conio.h>
struct node
{
int info;
struct node *lptr,*rptr;
};
struct node *nn,*dnode,*l,*r,*temp,*l1,*r1,*l2,*r2;;
int item;
void insfirdll()
{
nn=(struct node *)malloc(sizeof(struct node));
if(nn==NULL)
{
printf("\n memory not allocated:");
return;
}
printf("\n enter item:");
scanf("%d",&item);
nn->info=item;
if(l==NULL)
{
nn->lptr=NULL;
nn->rptr=NULL;
l=nn;
r=nn;
return;
}
nn->rptr=NULL;
nn->lptr=r;
r->rptr=nn;
r=nn;
}
void displaydll()
{
temp=l;
while(temp!=NULL)
{
printf("\n %d",temp->info);
temp=temp->rptr;
}
getch();
}
void splitdll()
{
if(l==NULL)
{
printf("\n list is empty:");
return;
}
while(l!=NULL)
{
if(l->info%2==0)
{
if(l1==NULL)
{
l1=l;
r1=l;
l1->lptr=NULL;
}
else
{
l->lptr=r1;
r1->rptr=l;
r1=l;
}
}
else
{
if(l2==NULL)
{
l2=l;
r2=l;
l2->lptr=NULL;
}
else
{
l->lptr=r2;
r2->rptr=l;
r2=l;
}
}
l=l->rptr;
}
r1->rptr=NULL;
r2->rptr=NULL;
}
void disoddlist()
{
temp=l1;
while(temp!=NULL)
{
printf("\n %d",temp->info);
temp=temp->rptr;
}
getch();
}
void disevenlist()
{
temp=l2;
while(temp!=NULL)
{
printf("\n %d",temp->info);
temp=temp->rptr;
}
getch();
}
void main()
{
int ch;
do
{
clrscr();
printf("\n 1)insert first");
printf("\n 2)display");
printf("\n 3)split");
printf("\n 4)display odd list");
printf("\n 5)display even list");
printf("\n enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 0:break;
case 1:insfirdll();
break;
case 2:displaydll();
break;
case 3:splitdll();
break;
case 4:disoddlist();
break;
case 5:disevenlist();
break;
default:printf("\n invalid input:");
getch();
}
}while(ch!=0);
}
#include<conio.h>
struct node
{
int info;
struct node *lptr,*rptr;
};
struct node *nn,*dnode,*l,*r,*temp,*l1,*r1,*l2,*r2;;
int item;
void insfirdll()
{
nn=(struct node *)malloc(sizeof(struct node));
if(nn==NULL)
{
printf("\n memory not allocated:");
return;
}
printf("\n enter item:");
scanf("%d",&item);
nn->info=item;
if(l==NULL)
{
nn->lptr=NULL;
nn->rptr=NULL;
l=nn;
r=nn;
return;
}
nn->rptr=NULL;
nn->lptr=r;
r->rptr=nn;
r=nn;
}
void displaydll()
{
temp=l;
while(temp!=NULL)
{
printf("\n %d",temp->info);
temp=temp->rptr;
}
getch();
}
void splitdll()
{
if(l==NULL)
{
printf("\n list is empty:");
return;
}
while(l!=NULL)
{
if(l->info%2==0)
{
if(l1==NULL)
{
l1=l;
r1=l;
l1->lptr=NULL;
}
else
{
l->lptr=r1;
r1->rptr=l;
r1=l;
}
}
else
{
if(l2==NULL)
{
l2=l;
r2=l;
l2->lptr=NULL;
}
else
{
l->lptr=r2;
r2->rptr=l;
r2=l;
}
}
l=l->rptr;
}
r1->rptr=NULL;
r2->rptr=NULL;
}
void disoddlist()
{
temp=l1;
while(temp!=NULL)
{
printf("\n %d",temp->info);
temp=temp->rptr;
}
getch();
}
void disevenlist()
{
temp=l2;
while(temp!=NULL)
{
printf("\n %d",temp->info);
temp=temp->rptr;
}
getch();
}
void main()
{
int ch;
do
{
clrscr();
printf("\n 1)insert first");
printf("\n 2)display");
printf("\n 3)split");
printf("\n 4)display odd list");
printf("\n 5)display even list");
printf("\n enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 0:break;
case 1:insfirdll();
break;
case 2:displaydll();
break;
case 3:splitdll();
break;
case 4:disoddlist();
break;
case 5:disevenlist();
break;
default:printf("\n invalid input:");
getch();
}
}while(ch!=0);
}