Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Doubly Linked List

Uploaded by

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

Doubly Linked List

Uploaded by

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

DOUBLY LINKED LIST:

Prev Data Next

Struct node

struct node*prev;

int data;

struct *next;

};

Create: Prev Next tail

new=(struct node*)malloc(size of struct node)); header NULL 10 2000


scanf(“%d”,&value) 1000 new node

new->prev=NULL;

new->data=value; Prev Next

new->next=NULL; 1000 20 3000


if(head==NULL) 2000 new node

head=new; 2000 30 NULL


tail=new; 3000

else

{
tail->next=new;

new->prev=tail;

tail=new;

DISPLAY:

temp=head 1000 NULL 10 2000


while(temp!=NULL)

1000 20 3000

{ 2000

printf(“%d”,temp->data)

temp=temp->next; 3000 2000 30 NULL


}

Insertion at beginning:

new=(struct node*)malloc(size of struct node));

scanf(“%d”,&value);

new->data=value;

new->prev=null;

new->next=head;

head->prev=new;

head=new;

Insertion at ending:

new=(struct node*)malloc(size of struct node));

scanf(“%d”,&value);

new->data=value;

new->next=null;

new->prev=tail;

tail->next=new;
tail=new;

DELETION

Beginning:

temp=head;

head=head->next;

temp->next=NULL;

head->prev=NULL;

Ending:

temp=tail;

tail=tail->prev;

temp->prev=NULL;

tail->next=NULL;

Deleting an element of specified location:

scanf(“%d”,&pos);

temp=head;

for(i=0;i<pos-1;i++)

temp=temp->next;

temp->next=temp->next->next;

temp->next->prev=temp;

You might also like