Jan

23

#include<stdio.h>

#include<conio.h>

#include<malloc.h>

struct node

{

int num;

struct node *next;

struct node *prev;

};

typedef struct node Node;

Node *temp,*start=NULL,*p;

void input();

void output();

void revoutput();

void insert();

void delet();

void main()

{

int choice;

clrscr();

do

{

printf(“\n 1 Creat\n”);

printf(“\n 2 Display\n”);

printf(“\n 3 Rev Display\n”);

printf(“\n 4 Insert\n”);

printf(“\n 5 Delete\n”);

printf(“\n 6 Exit\n”);

printf(“\n please enter your choice:- “);

scanf(“%d”,&choice);

switch(choice)

{

case 1: input();

break;

case 2: output();

break;

case 3: revoutput();

break;

case 4:insert();

break;

case 5:delet();

break;

case 6: exit(0);

}

}while(choice!=6);

getch();

}

void input()

{

temp=(Node*)malloc(sizeof(Node));

printf(“\n Enter a number:-“);

scanf(“%d”,&temp->num);

if(start==NULL)

{

temp->prev=NULL;

start=temp;

temp->next=NULL;

p=temp;

}

else

{

temp->next=NULL;

temp->prev=p;

p->next=temp;

p=temp;

}

}

void output()

{

temp=start;

printf(“\n Value of list\n”);

while(temp!=NULL)

{

printf(“%d\n”,temp->num);

temp=temp->next;

}

}

void revoutput()

{

Node *t,*r;

r=start;

printf(“\n Value in Rev orderlist list\n”);

while(r!=NULL)

{

t=r;

r=r->next;

}

while(t!=NULL)

{

printf(“%d\n”,t->num);

t=t->prev;

}

}

void insert()

{

int i,n;

Node *t;

printf(“\n enter the position where u want to insert:-“);

scanf(“%d”,&n);

temp=start;

p=(Node*)malloc(sizeof(Node));

printf(“\nEnter a new number:-“);

scanf(“%d”,&p->num);

if(n==1)

{

p->prev=NULL;

p->next=temp;

start=p;

temp->prev=p;

}

else

{

for(i=2;i<n;i++)

{

temp=temp->next;

}

p->next=temp->next;

temp->next=p;

p->prev=temp;

p->next->prev=p;

}

}

void delet()

{

int n;

Node *p;

printf(“\n Enter the value u want to delet:-“);

scanf(“%d”,&n);

temp= start;

while(temp!=NULL)

{

if(temp->num==n)

{

if(temp==start)

{

start=temp->next;

start->prev=NULL;

}

else

{

p->next=temp->next;

temp->next->prev=p;

}

free(temp);

break;

}

p=temp;

temp=temp->next;

}

}


Leave a Reply