Professional Documents
Culture Documents
#include<stdio.h> // J .#include<stdlib.h>
#include<process.h>
type def struct II 2.typedef struct
{
int num;
struct node *next;
struct node *prev;
}NODE;
int item;
nptr p;
p=(nptr)malloc(sizeof(item)); // 3. p=(nptr)malloc(sizeof(NODE));
printf("\n enter the item:");
sea nf(" ¾d ",&item);
p->num=item;
if(start--NULL)
{
sta rt=last=p;
p->prev=NULL;
p->next=NULL;
}
• else
{
p->next=start;
start->prev=p;
p->prev=NULL;
start=p;
}
}
// 4.void insert_end(TILE
*fp)
void insert_end(FILE *fp)
Page I
round3
int item;
nptr p;
p=( n ptr)ma lloc( sizeof(item)); II 5.p=(nptr)malloc(sizeof(NODE));
printf("\nentcr the item: ");
II 6. scanf("%d",&item);
scanf("%d" ,item);
scanf("%d" ,&pos);
res=count();
if(pos<= 111 pos>res)
{
printf("\n\ninsertion not possible");
}
else
{
Page 2
round3
printf(''\nenter the item : "):
p->num=item:
q=start;
q=q->next:
i++:
p->next=q->next;
q->next=p:
p->prev=q:
}
I
int count{)
{ int c=O:
nptrp;
p=~h• rt·:
while(p! =-NlJ I .L)
( p=p-> next;
c++;
n·turn ,:;
'
i
free( p );
}
cl."JC
{ nptr p;
p=start;
start=start->next;
start->prev=NULL;
printf("\ndclcted node: o/nd",p->num);
} li 1OJl'ff(pk
}
}
if(start last)
{ p=start;
sta rt=last=NULL;
printf("\n %dis deldeted",p->num);
frec(p);
}
• else
f p=last;
last->prcv->next=NULL;
last=last->next; ff 11.last=b.st->pn-, ·:
printf("\no/od is deleted",p->num):
free(p);
}
}
}
else
{
printf("\n enter position: ");
// 12. p=q=start;
res=countQ;
if(pos>=211 pos<=res) II 13. if(pos<=2 ll pos>=res)
{
printf("\n\nDeletion is not possible");
}
else
{
while(i<pos)
{q=p;
p=p->next;
i++;
}
q->next=p->next;
• p->next->pre\'=q;
printf("deleted node: %d",p->num);
free(p);
}
}
}
Page 5
round3
printf( "\nEmpty" );
}
else
{ nptr p;
p=start;
printf("ELEM ENTS ARE:-\n ");
while(p!=NULL)
{
printf("\n %d\n ",p->n um);
p=p->ncxt;
}
}
}
void reverse(FILE*fp)
{
if(start NULL)
{
printf("\nem pty" );
}
else
{
nptr p;
p=last;
while(p=NULL) // 14. while(p!=NULL)
{
printf(" \n%d",p->num);
p=p->prev; // J 5. p=p->prev;
}
}
}
Page 6
round3
void main()
{
int choice;
char ch~
printf("4: TRAVERSING\n");
do
{
scanf(" %d ".&choice);
switch(choice)
{
case 1: insert_hcg(fp);
break;
case 2: insert_end(fp);
break;
case 3: insert_spc(fp);
break;
case 4: traverse(fp);
break;
case 5: delete_beg(fp);
break;
case 6: delete_end(fp);
break;
case 7: delete_spe(fp);
break;
case 8: reverse(fp );
break;
case 9: exit(O);
default :
printf("\n\ninvalid choice");
}
Page 8
round3
printf( " \nDO r \\-A~T TO '10RE (Y or N)\n");
sc2nf(''%s'' .&ch);
Page 9