0% found this document useful (0 votes)
44 views3 pages

Doubly Linked List: Prakhar Singh (11BEC1108)

This document describes a doubly linked list data structure implemented in C. It includes functions to insert nodes into the list, display the list in normal or reverse order, and delete nodes from the list. The main function allows the user to choose these options in a menu-driven program to build and manipulate a doubly linked list.

Uploaded by

Prakhar Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views3 pages

Doubly Linked List: Prakhar Singh (11BEC1108)

This document describes a doubly linked list data structure implemented in C. It includes functions to insert nodes into the list, display the list in normal or reverse order, and delete nodes from the list. The main function allows the user to choose these options in a menu-driven program to build and manipulate a doubly linked list.

Uploaded by

Prakhar Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

DOUBLY LINKED LIST

PRAKHAR SINGH
(11BEC1108)

#include<conio.h>
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>

struct node{
int data;
struct node *llink,*rlink;
};

void insert(struct node **s,int num2);


void display(struct node *s);
void del(struct node *s,int num2);
int main()
{ struct node *m;
int num1,n;
char cho='y';
m=NULL;
while(cho=='y'||cho=='Y')
{ printf("1.insert\n2.delete\n3.display\n4.Exit");
scanf("%d",&n);
switch(n)
{ case 1:printf("Enter the number");
scanf("%d",&num1);
insert(&m,num1);
break;
case 2:printf("which num you want to delete:");
scanf("%d",&num1);
del(m,num1);
break;
case 3:display(m);
break;
case 4:exit(1);
break;
default :printf("wrong choice!!!");
}printf("do you want to continue");
scanf("%s",&cho);
}
getch();
}

void insert(struct node **s,int num2)


{ struct node *temp,*z;
if(*s==NULL)
{temp=(struct node *)malloc(sizeof(struct node));
temp->data=num2;
temp->llink=NULL;
temp->rlink=NULL;
*s=temp;
}
else
{temp=*s;
while(temp->rlink!=NULL)
temp=temp->rlink;

z=(struct node *)malloc(sizeof(struct node));


z->data=num2;
z->llink=temp;
z->rlink=NULL;
temp->rlink=z;
temp=z;
}
}
void display(struct node *s)
{ struct node *temp;
int n;
printf("1.normal view\n2.rev view");
scanf("%d",&n);
if(n==1)
{ temp=s;
printf("The num are");
while(temp->rlink!=NULL)
{printf("%d\n",temp->data);
temp=temp->rlink;
}
printf("%d\n",temp->data);
}
else
{ temp=s;
while(temp->rlink!=NULL)
temp=temp->rlink;
printf("The num are");
while(temp->llink!=NULL)
{printf("%d\n",temp->data);
temp=temp->llink;
}
printf("%d\n",temp->data);
}}

void del(struct node *s,int num2)


{ struct node *temp,*old;
temp=s;
while(temp!=NULL)
{if(temp->data==num2)
{old=temp->rlink;
temp->rlink->llink=old;
free(temp);
}
else
{old=temp;
temp=temp->rlink;
}
}

You might also like